From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ozlabs.org (ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id E092A1A0196 for ; Thu, 12 Mar 2015 16:02:10 +1100 (AEDT) Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AFF2F1401AC for ; Thu, 12 Mar 2015 16:02:10 +1100 (AEDT) Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Mar 2015 15:02:08 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id AFEB22BB004D for ; Thu, 12 Mar 2015 16:02:03 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2C51tII40370230 for ; Thu, 12 Mar 2015 16:02:03 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2C51TBB027177 for ; Thu, 12 Mar 2015 16:01:30 +1100 Date: Thu, 12 Mar 2015 16:01:05 +1100 From: Gavin Shan To: David Gibson Subject: Re: [PATCH 2/2] drivers/vfio: Support EEH error injection Message-ID: <20150312050105.GB28256@shangw> Reply-To: Gavin Shan References: <1426055651-22925-1-git-send-email-gwshan@linux.vnet.ibm.com> <1426055651-22925-2-git-send-email-gwshan@linux.vnet.ibm.com> <20150312005721.GP11973@voom.redhat.com> <20150312031642.GA15888@shangw> <20150312042129.GS11973@voom.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <20150312042129.GS11973@voom.redhat.com> Cc: kvm@vger.kernel.org, aik@ozlabs.ru, Gavin Shan , agraf@suse.de, linuxppc-dev@ozlabs.org, alex.williamson@redhat.com List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Thu, Mar 12, 2015 at 03:21:29PM +1100, David Gibson wrote: >On Thu, Mar 12, 2015 at 02:16:42PM +1100, Gavin Shan wrote: >> On Thu, Mar 12, 2015 at 11:57:21AM +1100, David Gibson wrote: >> >On Wed, Mar 11, 2015 at 05:34:11PM +1100, Gavin Shan wrote: >> >> The patch adds one more EEH sub-command (VFIO_EEH_PE_INJECT_ERR) >> >> to inject the specified EEH error, which is represented by >> >> (struct vfio_eeh_pe_err), to the indicated PE for testing purpose. >> >> >> >> Signed-off-by: Gavin Shan >> >> --- >> >> Documentation/vfio.txt | 47 ++++++++++++++++++++++++++++++------------- >> >> drivers/vfio/vfio_spapr_eeh.c | 14 +++++++++++++ >> >> include/uapi/linux/vfio.h | 34 ++++++++++++++++++++++++++++++- >> >> 3 files changed, 80 insertions(+), 15 deletions(-) >> >> >> >> diff --git a/Documentation/vfio.txt b/Documentation/vfio.txt >> >> index 96978ec..2e7f736 100644 >> >> --- a/Documentation/vfio.txt >> >> +++ b/Documentation/vfio.txt >> >> @@ -328,7 +328,13 @@ So 4 additional ioctls have been added: >> >> >> >> The code flow from the example above should be slightly changed: >> >> >> >> - struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op), .flags = 0 }; >> >> + struct vfio_eeh_pe_op *pe_op; >> >> + struct vfio_eeh_pe_err *pe_err; >> >> + >> >> + pe_op = malloc(sizeof(*pe_op) + sizeof(*pe_err)); >> >> + pe_err = (void *)pe_op + sizeof(*pe_op); >> >> + pe_op->argsz = sizeof(*pe_op) + sizeof(*pe_err); >> > >> >Surely that argsz can't be correct for most of the operations. The >> >extended structure should only be there for the error inject ioctl, >> >yes? >> > >> >> argsz isn't appropriate for most cases because kernel has the check >> "expected_argsz < passed_argsz", not "expected_argsz == >> passed_argsz". > >It works for now, but if any of those calls was extended with more >data, it would break horribly. By setting the argsz greater than >necessary, you're effectively passing uninitialized data to the >ioctl(). At the moment, the ioctl() ignores it, but the whole point >of the argsz value is that in the future, it might not. > Thank you for more explanation. I agree that it's worthy to pass precise argument size. I'll fix it as below in next revision: >> However, I'll fix it as follows to avoid confusion after collecting >> more comments: >> >> struct vfio_eeh_pe_op *pe_op; >> struct vfio_eeh_pe_err *pe_err; >> >> /* For all cases except error injection */ >> pe_op = malloc(sizeof(*pe_op)); >> pe_op->argsz = sizeof(*pe_op); >> >> /* For error injection case here */ >> pe_op = realloc(sizeof(*pe_op) + sizeof(*pe_err)); >> pe_op->argsz = sizeof(*pe_op) + sizeof(*pe_err); >> pe_err = (void *)pe_op + sizeof(*pe_op); >> Thanks, Gavin > >-- >David Gibson | I'll have my music baroque, and my code >david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ > | _way_ _around_! >http://www.ozlabs.org/~dgibson