Skip to content

Commit 3fad3a2

Browse files
nicolincawilliam
authored andcommitted
vfio/ap: Change saved_pfn to saved_iova
The vfio_ap_ops code maintains both nib address and its PFN, which is redundant, merely because vfio_pin/unpin_pages API wanted pfn. Since vfio_pin/unpin_pages() now accept "iova", change "saved_pfn" to "saved_iova" and remove pfn in the vfio_ap_validate_nib(). Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com> Tested-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Link: https://lore.kernel.org/r/20220723020256.30081-7-nicolinc@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 44abdd1 commit 3fad3a2

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void vfio_ap_wait_for_irqclear(int apqn)
112112
*
113113
* Unregisters the ISC in the GIB when the saved ISC not invalid.
114114
* Unpins the guest's page holding the NIB when it exists.
115-
* Resets the saved_pfn and saved_isc to invalid values.
115+
* Resets the saved_iova and saved_isc to invalid values.
116116
*/
117117
static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q)
118118
{
@@ -123,9 +123,9 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q)
123123
kvm_s390_gisc_unregister(q->matrix_mdev->kvm, q->saved_isc);
124124
q->saved_isc = VFIO_AP_ISC_INVALID;
125125
}
126-
if (q->saved_pfn && !WARN_ON(!q->matrix_mdev)) {
127-
vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_pfn << PAGE_SHIFT, 1);
128-
q->saved_pfn = 0;
126+
if (q->saved_iova && !WARN_ON(!q->matrix_mdev)) {
127+
vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_iova, 1);
128+
q->saved_iova = 0;
129129
}
130130
}
131131

@@ -189,27 +189,19 @@ static struct ap_queue_status vfio_ap_irq_disable(struct vfio_ap_queue *q)
189189
*
190190
* @vcpu: the object representing the vcpu executing the PQAP(AQIC) instruction.
191191
* @nib: the location for storing the nib address.
192-
* @g_pfn: the location for storing the page frame number of the page containing
193-
* the nib.
194192
*
195193
* When the PQAP(AQIC) instruction is executed, general register 2 contains the
196194
* address of the notification indicator byte (nib) used for IRQ notification.
197-
* This function parses the nib from gr2 and calculates the page frame
198-
* number for the guest of the page containing the nib. The values are
199-
* stored in @nib and @g_pfn respectively.
200-
*
201-
* The g_pfn of the nib is then validated to ensure the nib address is valid.
195+
* This function parses and validates the nib from gr2.
202196
*
203197
* Return: returns zero if the nib address is a valid; otherwise, returns
204198
* -EINVAL.
205199
*/
206-
static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, unsigned long *nib,
207-
unsigned long *g_pfn)
200+
static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)
208201
{
209202
*nib = vcpu->run->s.regs.gprs[2];
210-
*g_pfn = *nib >> PAGE_SHIFT;
211203

212-
if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *g_pfn)))
204+
if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *nib >> PAGE_SHIFT)))
213205
return -EINVAL;
214206

215207
return 0;
@@ -239,34 +231,34 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
239231
int isc,
240232
struct kvm_vcpu *vcpu)
241233
{
242-
unsigned long nib;
243234
struct ap_qirq_ctrl aqic_gisa = {};
244235
struct ap_queue_status status = {};
245236
struct kvm_s390_gisa *gisa;
246237
int nisc;
247238
struct kvm *kvm;
248-
unsigned long g_pfn, h_pfn;
239+
unsigned long h_pfn;
249240
phys_addr_t h_nib;
241+
dma_addr_t nib;
250242
int ret;
251243

252244
/* Verify that the notification indicator byte address is valid */
253-
if (vfio_ap_validate_nib(vcpu, &nib, &g_pfn)) {
254-
VFIO_AP_DBF_WARN("%s: invalid NIB address: nib=%#lx, g_pfn=%#lx, apqn=%#04x\n",
255-
__func__, nib, g_pfn, q->apqn);
245+
if (vfio_ap_validate_nib(vcpu, &nib)) {
246+
VFIO_AP_DBF_WARN("%s: invalid NIB address: nib=%pad, apqn=%#04x\n",
247+
__func__, &nib, q->apqn);
256248

257249
status.response_code = AP_RESPONSE_INVALID_ADDRESS;
258250
return status;
259251
}
260252

261-
ret = vfio_pin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1,
253+
ret = vfio_pin_pages(&q->matrix_mdev->vdev, nib, 1,
262254
IOMMU_READ | IOMMU_WRITE, &h_pfn);
263255
switch (ret) {
264256
case 1:
265257
break;
266258
default:
267259
VFIO_AP_DBF_WARN("%s: vfio_pin_pages failed: rc=%d,"
268-
"nib=%#lx, g_pfn=%#lx, apqn=%#04x\n",
269-
__func__, ret, nib, g_pfn, q->apqn);
260+
"nib=%pad, apqn=%#04x\n",
261+
__func__, ret, &nib, q->apqn);
270262

271263
status.response_code = AP_RESPONSE_INVALID_ADDRESS;
272264
return status;
@@ -296,12 +288,12 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
296288
case AP_RESPONSE_NORMAL:
297289
/* See if we did clear older IRQ configuration */
298290
vfio_ap_free_aqic_resources(q);
299-
q->saved_pfn = g_pfn;
291+
q->saved_iova = nib;
300292
q->saved_isc = isc;
301293
break;
302294
case AP_RESPONSE_OTHERWISE_CHANGED:
303295
/* We could not modify IRQ setings: clear new configuration */
304-
vfio_unpin_pages(&q->matrix_mdev->vdev, g_pfn << PAGE_SHIFT, 1);
296+
vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
305297
kvm_s390_gisc_unregister(kvm, isc);
306298
break;
307299
default:

drivers/s390/crypto/vfio_ap_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ struct ap_matrix_mdev {
9999
* struct vfio_ap_queue - contains the data associated with a queue bound to the
100100
* vfio_ap device driver
101101
* @matrix_mdev: the matrix mediated device
102-
* @saved_pfn: the guest PFN pinned for the guest
102+
* @saved_iova: the notification indicator byte (nib) address
103103
* @apqn: the APQN of the AP queue device
104104
* @saved_isc: the guest ISC registered with the GIB interface
105105
*/
106106
struct vfio_ap_queue {
107107
struct ap_matrix_mdev *matrix_mdev;
108-
unsigned long saved_pfn;
108+
dma_addr_t saved_iova;
109109
int apqn;
110110
#define VFIO_AP_ISC_INVALID 0xff
111111
unsigned char saved_isc;

0 commit comments

Comments
 (0)