From patchwork Mon Dec 23 16:43:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11308521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41C89109A for ; Mon, 23 Dec 2019 16:46:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E2452073A for ; Mon, 23 Dec 2019 16:46:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="KwLHx/uJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E2452073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQoA-0006Kn-Kd; Mon, 23 Dec 2019 16:43:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQo8-0006KG-V5 for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 16:43:48 +0000 X-Inumbo-ID: 5c36a6da-25a3-11ea-96fe-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5c36a6da-25a3-11ea-96fe-12813bfff9fa; Mon, 23 Dec 2019 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577119414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vsbhqvxTPqxq150MwF1GoyaiUXnxXCxdKv0AX0i+w4A=; b=KwLHx/uJU2tWJiLH6hKiz+Bk10NTE1NbIwHv0OjtSqwLMlKinKcHckWq /Tl0KWaPupeTJygqSvH2nWD8lmGHj3WTko3MpYXsCuToXTzYu7wnIp5jb r/PE3QBq3Ek0jAUyPhN7m3gM6y4LFnvpSR6Hhh5ZKQnFkMIthiZII2rDj s=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7yCzjNOIXE9cMcr2KHNYPhVUxnpjVBL9i5LUbLITtj9830IRWyE98T/XwFbO7hF793u7hLd/tS q8p+dsEsxrvEFZ/4obU8sk3o29Uhrk3svBGG2iIixBy5nMCAr8jO//ZaXHLtzSa8g2dVFLGq7Q R87ogzktdYXJ20D9IIoiBylAWOL37ekWC0TnFAk8yFGULHoyotomVSFNhHeAD29CWZPNtwO0uG TU6ES15VDEM4Yys1DFw5vWSgqjQEh0YXtvigmkZ2pOHLdCmphj80Q9y1FYVY1tqUhUgZHF2o/F FVg= X-SBRS: 2.7 X-MesageID: 10229662 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,348,1571716800"; d="scan'208";a="10229662" From: George Dunlap To: Date: Mon, 23 Dec 2019 16:43:26 +0000 Message-ID: <20191223164329.3113378-2-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191223164329.3113378-1-george.dunlap@citrix.com> References: <20191223164329.3113378-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/4] xen: Remove trailing whitespace from time.c X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes. Signed-off-by: George Dunlap Acked-by: Jan Beulich --- CC: Andrew Cooper CC: Jan Beulich --- xen/arch/x86/time.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index ea696a95e8..64e471a39b 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1,10 +1,10 @@ /****************************************************************************** * arch/x86/time.c - * + * * Per-CPU time calibration and management. - * + * * Copyright (c) 2002-2005, K A Fraser - * + * * Portions from Linux are: * Copyright (c) 1991, 1992, 1995 Linus Torvalds */ @@ -78,8 +78,8 @@ static struct timer calibration_timer; * We simulate a 32-bit platform timer from the 16-bit PIT ch2 counter. * Otherwise overflow happens too quickly (~50ms) for us to guarantee that * softirq handling will happen in time. - * - * The pit_lock protects the 16- and 32-bit stamp fields as well as the + * + * The pit_lock protects the 16- and 32-bit stamp fields as well as the */ static DEFINE_SPINLOCK(pit_lock); static u16 pit_stamp16; @@ -100,7 +100,7 @@ static inline u32 div_frac(u32 dividend, u32 divisor) { u32 quotient, remainder; ASSERT(dividend < divisor); - asm ( + asm ( "divl %4" : "=a" (quotient), "=d" (remainder) : "0" (0), "1" (dividend), "r" (divisor) ); @@ -1011,7 +1011,7 @@ static void __get_cmos_time(struct rtc_time *rtc) rtc->day = CMOS_READ(RTC_DAY_OF_MONTH); rtc->mon = CMOS_READ(RTC_MONTH); rtc->year = CMOS_READ(RTC_YEAR); - + if ( RTC_ALWAYS_BCD || !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) ) { BCD_TO_BIN(rtc->sec); @@ -1511,8 +1511,8 @@ static void check_tsc_warp(unsigned long tsc_khz, unsigned long *max_warp) spin_unlock(&sync_lock); /* - * Be nice every now and then (and also check whether measurement is - * done [we also insert a 10 million loops safety exit, so we dont + * Be nice every now and then (and also check whether measurement is + * done [we also insert a 10 million loops safety exit, so we dont * lock up in case the TSC readout is totally broken]): */ if ( unlikely(!(i & 7)) ) @@ -1524,7 +1524,7 @@ static void check_tsc_warp(unsigned long tsc_khz, unsigned long *max_warp) } /* - * Outside the critical section we can now see whether we saw a + * Outside the critical section we can now see whether we saw a * time-warp of the TSC going backwards: */ if ( unlikely(prev > now) ) @@ -1806,11 +1806,11 @@ void init_percpu_time(void) } /* - * On certain older Intel CPUs writing the TSC MSR clears the upper 32 bits. + * On certain older Intel CPUs writing the TSC MSR clears the upper 32 bits. * Obviously we must not use write_tsc() on such CPUs. * - * Additionally, AMD specifies that being able to write the TSC MSR is not an - * architectural feature (but, other than their manual says, also cannot be + * Additionally, AMD specifies that being able to write the TSC MSR is not an + * architectural feature (but, other than their manual says, also cannot be * determined from CPUID bits). */ static void __init tsc_check_writability(void) @@ -2010,7 +2010,7 @@ void __init early_time_init(void) do_div(tmp, 1000); cpu_khz = (unsigned long)tmp; - printk("Detected %lu.%03lu MHz processor.\n", + printk("Detected %lu.%03lu MHz processor.\n", cpu_khz / 1000, cpu_khz % 1000); setup_irq(0, 0, &irq0); @@ -2025,7 +2025,7 @@ static int _disable_pit_irq(void(*hpet_broadcast_setup)(void)) return -1; /* - * If we do not rely on PIT CH0 then we can use HPET for one-shot timer + * If we do not rely on PIT CH0 then we can use HPET for one-shot timer * emulation when entering deep C states. * XXX dom0 may rely on RTC interrupt delivery, so only enable * hpet_broadcast if FSB mode available or if force_hpet_broadcast. From patchwork Mon Dec 23 16:43:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11308511 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C371B109A for ; Mon, 23 Dec 2019 16:45:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9EAD42073A for ; Mon, 23 Dec 2019 16:45:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="VkLNS03a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EAD42073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQo5-0006J1-B5; Mon, 23 Dec 2019 16:43:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQo3-0006Id-VA for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 16:43:43 +0000 X-Inumbo-ID: 5bbafdb4-25a3-11ea-96fe-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5bbafdb4-25a3-11ea-96fe-12813bfff9fa; Mon, 23 Dec 2019 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577119414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4LajtYjbMp6EySa6REpYUzL+FBkEHu6GtKsC0g+RZ1c=; b=VkLNS03auYBPUxa4z5ruzmcRWIi5To29A0hBDVoa4diQttgFcehaCh7d 86wFrN6/j0wYdnpXpSepG4qq3Wra4GTssSjirMxOtoDU7lW0AJ/S1WtVX E9STo4BjQXjokrAzUzgfisnlVYBvn2a+Ou4r18vuNpotEDsw6E25CcWmj k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: AxsFZfHdjC5LEZb4P+WEb/mOM+GeGKy4uTMsLWWzIUTaafKoQS8ilxHcMLF+7CpZtU+6BTPe61 /vSJFaMh/xJdpaYiutyWAijRme/t+fq3S0XaE9DUs77KvFflBusgA/oDxIKtmKlh8doBfmYR31 aDkTUbyAKgUpELHrwMsAAM3/wWhWQAencHg60V6NbgkK5llQudM/9kqE11NBIWwThXrHzZnsqV 9X3TjNGIHtHmM11DJZdPd23AgG5zSsSY32GBFUbQ4KFdKLfqi+aL7gVxCm7hQXbrl1M38icCwn 36A= X-SBRS: 2.7 X-MesageID: 10229661 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,348,1571716800"; d="scan'208";a="10229661" From: George Dunlap To: Date: Mon, 23 Dec 2019 16:43:27 +0000 Message-ID: <20191223164329.3113378-3-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191223164329.3113378-1-george.dunlap@citrix.com> References: <20191223164329.3113378-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/4] xen: Add 'synthetic' preemption check parameter X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In order to better test hypervisor preemption paths, add an option to artificially increase the number of preemptions. While modifying xen-command-line.pandoc, escape some underscores, and remove some trailing whitespace. Signed-off-by: George Dunlap --- CC: Andrew Cooper CC: Jan Beulich --- docs/misc/xen-command-line.pandoc | 20 ++++++++++++++++++-- xen/arch/x86/time.c | 11 +++++++++++ xen/include/xen/sched.h | 10 +++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 981a5e2381..1a9fda8627 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -636,13 +636,29 @@ Available alternatives, with their meaning, are: Specify the USB controller to use, either by instance number (when going over the PCI busses sequentially) or by PCI device (must be on segment 0). -### debug_stack_lines +### debug\_stack\_lines > `= ` > Default: `20` Limits the number lines printed in Xen stack traces. +### debug-synthetic-preemption +> `= ` + +> Default: `0` + +Artificially increases rate at which `hypercall_preempt_check()` +returns `true`, for debugging purposes, to a rate of one in `N`. (The +default, `0`, disables the feature.) + +When promoting pagetables, for instance, `hypercall_preempt_check()` +is called before processing each PTE. Since there are 512 PTEs per +page, a value of `1024` should result in pagetable promotion being +interrupted every other page on average. + +Only available in DEBUG builds. + ### debugtrace > `= [cpu:]` @@ -1690,7 +1706,7 @@ The following resources are available: CDP, one COS will corespond two CBMs other than one with CAT, due to the sum of CBMs is fixed, that means actual `cos_max` in use will automatically reduce to half when CDP is enabled. - + ### pv-linear-pt (x86) > `= ` diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 64e471a39b..34302f81e7 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -43,6 +43,17 @@ static char __initdata opt_clocksource[10]; string_param("clocksource", opt_clocksource); +#ifndef NDEBUG +int debug_synthetic_preemption = 0; +integer_param("debug-synthetic-preemption", debug_synthetic_preemption); + +bool synthetic_preemption_check(void) { + if ( debug_synthetic_preemption == 0 ) + return false; + return !(rdtsc() % debug_synthetic_preemption); +} +#endif + unsigned long __read_mostly cpu_khz; /* CPU clock frequency in kHz. */ DEFINE_SPINLOCK(rtc_lock); unsigned long pit0_ticks; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 9f7bc69293..c0071eee04 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -748,6 +748,13 @@ static inline void hypercall_cancel_continuation(struct vcpu *v) v->hcall_preempted = false; } +#ifndef NDEBUG +bool synthetic_preemption_check(void); +#define synthetic_preemption_check synthetic_preemption_check +#else +#define synthetic_preempiton_check() false +#endif + /* * For long-running operations that must be in hypercall context, check * if there is background work to be done that should interrupt this @@ -755,7 +762,8 @@ static inline void hypercall_cancel_continuation(struct vcpu *v) */ #define hypercall_preempt_check() (unlikely( \ softirq_pending(smp_processor_id()) | \ - local_events_need_delivery() \ + local_events_need_delivery() | \ + synthetic_preemption_check() \ )) /* From patchwork Mon Dec 23 16:43:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11308509 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C34E8109A for ; Mon, 23 Dec 2019 16:44:57 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F6802073A for ; Mon, 23 Dec 2019 16:44:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="JzdaddEB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F6802073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQo0-0006Ht-0p; Mon, 23 Dec 2019 16:43:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQny-0006Hg-VI for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 16:43:38 +0000 X-Inumbo-ID: 5ac53912-25a3-11ea-96fe-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5ac53912-25a3-11ea-96fe-12813bfff9fa; Mon, 23 Dec 2019 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577119414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7vWp9GkW3ug+BLCdr2aqVvMT7j7OYz0ptK5b/xJThzk=; b=JzdaddEBp2gfFrj9Sge4mRu0EsTJrDoAZZ2dmN4nP2f6w37UlcPdrr+O ni1lqLtlxuD904m9cJKYjMR9N8V9o3qRGPsMgA5G8mogU+0jPKMCmodqK b/oVARpUqyKZQhEOSJM0gRl00fIBGfsaXemsLAOrqBDEjvJP2kpO/T8+S o=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 1ngXjC+DlOsqHUXA2V84RYcwdaRuaVODbDhbte0npTb8cVe9u0mcKyBEcYtcUlhXtBzHoQVgDJ ILjBaO49C6Mo2jJTfxcT/D3sGnR5Hoc9RpyakuSohggTk4mMTHaucVcSzroBp3HaM10lVR1gtJ w8AeWQAZ7+c1a/C54NIew76cRZ+u98qJZMblkF28sEhspZnxVCT2n1wOe5eyeoxck7IptGAfRJ FuBrgA5dUcmZ4LNavMm/YFvSqnTelgFKTS5jyZDLVRMxIUUNF0znCXGRO7djoDUOHs1Mei98sp LOo= X-SBRS: 2.7 X-MesageID: 10229660 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,348,1571716800"; d="scan'208";a="10229660" From: George Dunlap To: Date: Mon, 23 Dec 2019 16:43:28 +0000 Message-ID: <20191223164329.3113378-4-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191223164329.3113378-1-george.dunlap@citrix.com> References: <20191223164329.3113378-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/4] mm: Use put_old_guest_table for relinquish_pages X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" relinquish_pages() deals with interrupted de-validation in a fairly ad-hoc way, by either re-setting PGT_pinned (in the case of EINTR) or letting the page "fall through" to the "force invalidate" loop below. This requires an extensive comment describing what needs to happen to the type and count in each case, and why each works. Additionally, it turns out that at this point, the "force invalidate" loop is only required to handle this ad-hoc continuation. Replace this with the 'standard' way of dealing with restarting pages, old_guest_table. Call put_old_guest_table(current) at the top of the function, and set current->arch.old_guest_table* as appropriate. This code is simpler, and mirrors other old_guest_table code in mm.c. It will also allow us to remove the force-invalidate loop entirely in a subsequent patch. While here, make the refcounting logic a bit easier to follow: We always drop the general reference held by PGT_pinned, regardless of what happens to the type count. Rather than manually re-dropping the refcount if put_page_and_type_preemptible() fails, just drop the refcount unconditionally, and call put_page_type_preemptible() instead. Signed-off-by: George Dunlap Reviewed-by: Jan Beulich --- CC: Andrew Cooper CC: Jan Beulich --- xen/arch/x86/domain.c | 50 +++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index d9c63379cd..b7968463cb 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1953,6 +1953,10 @@ static int relinquish_memory( unsigned long x, y; int ret = 0; + ret = put_old_guest_table(current); + if ( ret ) + return ret; + /* Use a recursive lock, as we may enter 'free_domheap_page'. */ spin_lock_recursive(&d->page_alloc_lock); @@ -1967,42 +1971,32 @@ static int relinquish_memory( } if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) ) - ret = put_page_and_type_preemptible(page); + { + /* Always drop the page ref associated with PGT_pinned */ + put_page(page); + ret = put_page_type_preemptible(page); + } switch ( ret ) { case 0: break; - case -ERESTART: case -EINTR: - /* - * -EINTR means PGT_validated has been re-set; re-set - * PGT_pinned again so that it gets picked up next time - * around. - * - * -ERESTART, OTOH, means PGT_partial is set instead. Put - * it back on the list, but don't set PGT_pinned; the - * section below will finish off de-validation. But we do - * need to drop the general ref associated with - * PGT_pinned, since put_page_and_type_preemptible() - * didn't do it. - * - * NB we can do an ASSERT for PGT_validated, since we - * "own" the type ref; but theoretically, the PGT_partial - * could be cleared by someone else. - */ - if ( ret == -EINTR ) - { - ASSERT(page->u.inuse.type_info & PGT_validated); - set_bit(_PGT_pinned, &page->u.inuse.type_info); - } - else - put_page(page); + ASSERT(page->u.inuse.type_info & PGT_validated); + /* Fallthrough */ + case -ERESTART: + current->arch.old_guest_ptpg = NULL; + current->arch.old_guest_table = page; + current->arch.old_guest_table_partial = (ret == -ERESTART); ret = -ERESTART; - /* Put the page back on the list and drop the ref we grabbed above */ - page_list_add(page, list); - put_page(page); + /* Make sure we don't lose track of the page */ + page_list_add_tail(page, &d->arch.relmem_list); + + /* + * NB that we've transferred the general ref acquired at + * the top of the loop to old_guest_table. + */ goto out; default: BUG(); From patchwork Mon Dec 23 16:43:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11308517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C169A109A for ; Mon, 23 Dec 2019 16:45:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E4D72073A for ; Mon, 23 Dec 2019 16:45:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="e0cjfsJQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E4D72073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQoF-0006Mf-3t; Mon, 23 Dec 2019 16:43:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijQoE-0006MM-1b for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 16:43:54 +0000 X-Inumbo-ID: 5bbafdb5-25a3-11ea-96fe-12813bfff9fa Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5bbafdb5-25a3-11ea-96fe-12813bfff9fa; Mon, 23 Dec 2019 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577119415; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AZQ3x3k2kqbsUYZ1QjMtwFE51Vo18atykQNPnlW1pg4=; b=e0cjfsJQi2erxh0m7YcP3+XtwiokzdQl6bah5eOHg+NaFGEpV6yDzwSv ZiQBiqjwi+Ha89Fm6OMP1QvDLJeWTIIGdAP2MmaxdsPe/M5J8zYql0R17 lIcpKFq1ejONpG1R1CcS6wM14PRzjeUI7fnHdgtBM8XGxGPvXvsi7cl3x g=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: rDAD6UMyiKDpv9n+segRvegA9NQBvFAA75lfhPztGHXaYzHGQRxmmPL4VR/PRBHyIxNn5GkHJB Ghipv7stAMoJa3nCkW78oOLQJBV6Yr1YmbHyFezg6McZpTLATf1wvq6G/Ec4YCSgD2MrzeQ1SL V9ggY8UUkOpaQJuUF+C7D+lLbUbwWfUMJ4DAhCLW/SuOaSfNeqWVBTiPeyRDW98suB8Wa43kqn VFFBJPoevBvMv1aGy5541xG0zwyeGoD8P6bpjUcwuOhZ4jq0EJQCnvDDFyQIk9qimCWSCAnibU HJA= X-SBRS: 2.7 X-MesageID: 10229663 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,348,1571716800"; d="scan'208";a="10229663" From: George Dunlap To: Date: Mon, 23 Dec 2019 16:43:29 +0000 Message-ID: <20191223164329.3113378-5-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191223164329.3113378-1-george.dunlap@citrix.com> References: <20191223164329.3113378-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/4] x86/mm: Remove force-invalidate loop X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The comment about the "force-invalidate" loop gives two reasons for its existence: 1. Breaking circular "linear pagetable" references 2. Cleaning up partially-validated pages. The first reason been invalid since XSA-240: Since then it hasn't been possible to generate circular linear pagetable references. The second reason has been invalid since long before that: Before calling relinquish_memory(), domain_relinquish_resources() calls vcpu_destroy_pagetables() on each vcpu; this will in turn call put_old_guest_table() on each vcpu. The result should be that it's not possible to have top-level partially-devalidated pagetables by the time we get to relinquish_memory(). The loop, it turns out, was effectively there only to pick up interrupted UNPIN operations of relinquish_memory() itself. Now that these are being handled by put_old_guest_table(), we can remove this loop entirely. Signed-off-by: George Dunlap --- This patch has the advantage that it doesn't hide mis-accounted partial pages anymore; but has the disadvantage that if there *is* such a mis-accounting, it will become a resource leak (and thus an XSA). It might be a good idea to add another "clean up partial pages" pass after all other pages have been cleaned up, with a suitable ASSERT(). That way we have a higher chance of catching mis-accounting during development, without risking opening up a memory / domain leak in production. CC: Andrew Cooper CC: Jan Beulich --- xen/arch/x86/domain.c | 71 ------------------------------------------- 1 file changed, 71 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index b7968463cb..847a70302c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1950,7 +1950,6 @@ static int relinquish_memory( struct domain *d, struct page_list_head *list, unsigned long type) { struct page_info *page; - unsigned long x, y; int ret = 0; ret = put_old_guest_table(current); @@ -2004,76 +2003,6 @@ static int relinquish_memory( put_page_alloc_ref(page); - /* - * Forcibly invalidate top-most, still valid page tables at this point - * to break circular 'linear page table' references as well as clean up - * partially validated pages. This is okay because MMU structures are - * not shared across domains and this domain is now dead. Thus top-most - * valid tables are not in use so a non-zero count means circular - * reference or partially validated. - */ - y = page->u.inuse.type_info; - for ( ; ; ) - { - x = y; - if ( likely((x & PGT_type_mask) != type) || - likely(!(x & (PGT_validated|PGT_partial))) ) - break; - - y = cmpxchg(&page->u.inuse.type_info, x, - x & ~(PGT_validated|PGT_partial)); - if ( likely(y == x) ) - { - /* No need for atomic update of type_info here: noone else updates it. */ - switch ( ret = devalidate_page(page, x, 1) ) - { - case 0: - break; - case -EINTR: - page_list_add(page, list); - page->u.inuse.type_info |= PGT_validated; - if ( x & PGT_partial ) - put_page(page); - put_page(page); - ret = -ERESTART; - goto out; - case -ERESTART: - page_list_add(page, list); - /* - * PGT_partial holds a type ref and a general ref. - * If we came in with PGT_partial set, then we 1) - * don't need to grab an extra type count, and 2) - * do need to drop the extra page ref we grabbed - * at the top of the loop. If we didn't come in - * with PGT_partial set, we 1) do need to drab an - * extra type count, but 2) can transfer the page - * ref we grabbed above to it. - * - * Note that we must increment type_info before - * setting PGT_partial. Theoretically it should - * be safe to drop the page ref before setting - * PGT_partial, but do it afterwards just to be - * extra safe. - */ - if ( !(x & PGT_partial) ) - page->u.inuse.type_info++; - smp_wmb(); - page->u.inuse.type_info |= PGT_partial; - if ( x & PGT_partial ) - put_page(page); - goto out; - default: - BUG(); - } - if ( x & PGT_partial ) - { - page->u.inuse.type_info--; - put_page(page); - } - break; - } - } - /* Put the page on the list and /then/ potentially free it. */ page_list_add_tail(page, &d->arch.relmem_list); put_page(page);