From patchwork Fri Apr 29 09:42:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 8979251 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 27C319F39D for ; Fri, 29 Apr 2016 09:45:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F8DE20212 for ; Fri, 29 Apr 2016 09:45:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36BC3201C0 for ; Fri, 29 Apr 2016 09:45:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aw4x5-00038d-W9; Fri, 29 Apr 2016 09:43:11 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aw4x4-00038W-BK for xen-devel@lists.xenproject.org; Fri, 29 Apr 2016 09:43:10 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 91/53-28710-DAC23275; Fri, 29 Apr 2016 09:43:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRWlGSWpSXmKPExsUyZ7p8oO5aHeV wg1/feCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxbR9czF8wRrTjQt4a1gXGrYBcjF4eQQAeT xJFNJ1ghnC+MEttnr2WEcDYySjz8/48FwulmlJg1cSJbFyMnkFMksWjxMqYuRg4ONgETiTerH EHCIgJKEvdWTWYCqWcWeMwsseTUUUaQGmGBNIl/31lAalgEVCVu3NrODmLzCrhJ9Nz4BFYiIS AnseBCOkRYUOLkzCcsIGFmAXWJ9fOEQMLMAtoSyxa+ZgaxJQSMJdrfXmSbwCgwC0nHLISOWUg 6FjAyr2LUKE4tKkst0jU01ksqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAxOBiDY wfhvm+chRkkOJiVR3hBO5XAhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKEryR2kA5waLU9NSKtMwcY JzApCU4eJREeE9pAaV5iwsSc4sz0yFSpxgVpcR5g0D6BEASGaV5cG2w2LzEKCslzMsIdIgQT0 FqUW5mCar8K0ZxDkYlYd7pIFN4MvNK4Ka/AlrMBLRYYJMiyOKSRISUVAPj5OtSZQEZ+tJv/t7 vSD/6USN9W5RVaaSv/WXV4gqdW52XcydMbvqd+vQWv5mVb7gui8j8Y/nXp+Rn3dTemP9Qg61j w0OPtTvbld9MSLLpymTI43baaul4RWXdh9gd6T82b3NPOTUjfr7UrHopgw0LYvhzPj8s5uAud GeXnPh38zFeg3d5fp1KLMUZiYZazEXFiQAl8LujyAIAAA== X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1461922987!715367!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14974 invoked from network); 29 Apr 2016 09:43:08 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 29 Apr 2016 09:43:08 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u3T9h2Q7011044 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Apr 2016 09:43:02 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id u3T9h1OL001759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Apr 2016 09:43:02 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u3T9h0r6018919; Fri, 29 Apr 2016 09:43:00 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Apr 2016 02:43:00 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 1B41F6A0107; Fri, 29 Apr 2016 05:42:59 -0400 (EDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org Date: Fri, 29 Apr 2016 05:42:35 -0400 Message-Id: <1461922955-16207-1-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Ross Lagerwall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v2] xsplice: Don't perform multiple operations on same payload once work is scheduled. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently it is possible to: 1) xc_xsplice_apply() \-> xsplice_action spin_lock(payload_lock) \- schedule_work() spin_unlock(payload_lock); 2) xc_xsplice_unload() \-> xsplice_action spin_lock(payload_lock) free_payload(data); spin_unlock(payload_lock); .. all CPUs are quiesced. 3) check_for_xsplice_work() \-> apply_payload \-> arch_xsplice_apply_jmp BOOM The reason is that state is in 'CHECKED' which changes to 'APPLIED' once check_for_xsplice_work finishes. So we have a race between 1) -> 3) where one can manipulate the payload. To guard against this we add a check in xsplice_action to not allow any actions if schedule_work has been called for this specific payload. The function 'is_work_scheduled' checks xsplice_work which is safe as: - The ->do_work changes to 1 under the payload_lock (which we also hold). - The ->do_work changes to 0 when all CPUs are quisced and IRQs have been disabled. Signed-off-by: Konrad Rzeszutek Wilk Reported-and-Tested-by: Roger Pau Monné Reviewed-by: Andrew Cooper --- Cc: Roger Pau Monné Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu Cc: Ross Lagerwall --- --- xen/common/xsplice.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 1b67d39..777faa7 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -1099,6 +1099,13 @@ static void xsplice_do_action(void) data->rc = rc; } +static bool_t is_work_scheduled(const struct payload *data) +{ + ASSERT(spin_is_locked(&payload_lock)); + + return xsplice_work.do_work && xsplice_work.data == data; +} + static int schedule_work(struct payload *data, uint32_t cmd, uint32_t timeout) { ASSERT(spin_is_locked(&payload_lock)); @@ -1363,6 +1370,12 @@ static int xsplice_action(xen_sysctl_xsplice_action_t *action) return PTR_ERR(data); } + if ( is_work_scheduled(data) ) + { + rc = -EBUSY; + goto out; + } + switch ( action->cmd ) { case XSPLICE_ACTION_UNLOAD: @@ -1423,6 +1436,7 @@ static int xsplice_action(xen_sysctl_xsplice_action_t *action) break; } + out: spin_unlock(&payload_lock); return rc;