From patchwork Wed Jan 29 14:38:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11356279 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 36A5C1395 for ; Wed, 29 Jan 2020 14:39:52 +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 12A8A206F0 for ; Wed, 29 Jan 2020 14:39:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="pTuDUC6b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12A8A206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1iwoUW-0005r7-5M; Wed, 29 Jan 2020 14:38:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwoUU-0005qo-BH for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 14:38:50 +0000 X-Inumbo-ID: 100ccaf4-42a5-11ea-8396-bc764e2007e4 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 100ccaf4-42a5-11ea-8396-bc764e2007e4; Wed, 29 Jan 2020 14:38:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1580308730; x=1611844730; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+0j9VGZpo7pomx+fEDAabRHRZmzylb3yl1hZBMMYBOM=; b=pTuDUC6b2Y8n8JniJ0OBCVNuakOOiKP7FLxKyrTD+GgzenQKOsrLv2jg oWznGhqDcoEDe5Spq3a7KuTA76GnABFTAaGYFR1OtVI4sYRQmRA7hLPuV GBKt+zo7loU8/TkEM3SjkTLWYXuyFVjSoZkAq95Ik+RZLPrLlSukZmPIu A=; IronPort-SDR: ZBTE9fA13hqIMXtHojxENadLU5qF+yGcwSRUKLL3QbkSJQg/5ghe3PCGGctd8evRZcNfdGdIEv 05PliOd7SPcg== X-IronPort-AV: E=Sophos;i="5.70,378,1574121600"; d="scan'208";a="13406334" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 29 Jan 2020 14:38:46 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id 938CBA24B0; Wed, 29 Jan 2020 14:38:44 +0000 (UTC) Received: from EX13D32EUC001.ant.amazon.com (10.43.164.159) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Wed, 29 Jan 2020 14:38:44 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D32EUC001.ant.amazon.com (10.43.164.159) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 29 Jan 2020 14:38:43 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 29 Jan 2020 14:38:40 +0000 From: Paul Durrant To: Date: Wed, 29 Jan 2020 14:38:29 +0000 Message-ID: <20200129143831.1369-3-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129143831.1369-1-pdurrant@amazon.com> References: <20200129143831.1369-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v6 2/4] mm: modify domain_adjust_tot_pages() to better handle a zero adjustment X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Paul Durrant , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently the function will pointlessly acquire and release the global 'heap_lock' in this case. NOTE: No caller yet calls domain_adjust_tot_pages() with a zero 'pages' argument, but a subsequent patch will make this possible. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Wei Liu v6: - Modify memory_exchange() v5: - Split out from the subsequent 'make MEMF_no_refcount pages safe to assign' patch as requested by Jan --- xen/common/memory.c | 3 +-- xen/common/page_alloc.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index c7d2bac452..a4a5374d26 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -727,8 +727,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) (j * (1UL << exch.out.extent_order))); spin_lock(&d->page_alloc_lock); - drop_dom_ref = (dec_count && - !domain_adjust_tot_pages(d, -dec_count)); + drop_dom_ref = !domain_adjust_tot_pages(d, -dec_count); spin_unlock(&d->page_alloc_lock); if ( drop_dom_ref ) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 919a270587..135e15bae0 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -460,6 +460,9 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages) { long dom_before, dom_after, dom_claimed, sys_before, sys_after; + if ( !pages ) + goto out; + ASSERT(spin_is_locked(&d->page_alloc_lock)); d->tot_pages += pages;