From patchwork Mon Feb 4 18:15:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10796319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3481413B4 for ; Mon, 4 Feb 2019 18:15:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E9882B720 for ; Mon, 4 Feb 2019 18:15:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12ACF2B7F8; Mon, 4 Feb 2019 18:15:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DEAA2B720 for ; Mon, 4 Feb 2019 18:15:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8870A8E004F; Mon, 4 Feb 2019 13:15:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8668D8E001C; Mon, 4 Feb 2019 13:15:43 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 772E88E004F; Mon, 4 Feb 2019 13:15:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 384808E001C for ; Mon, 4 Feb 2019 13:15:43 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id h10so452917plk.12 for ; Mon, 04 Feb 2019 10:15:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=zqElbD91wN7xrII3yrqdT2po60YKbiGuJ5EuHOboq08=; b=Jk6ja96yxRte8pIdsHAQkbZeTqr4Tuy/z1Vqb29QzNOGW6JNihRrt4vQ4z0DUgEEWY lC1rZxKRT4chNOB0WVg6pjL/5saS5LQr7ZvaMCXe6+86s/Jpdkz/fdgyuxcp3BZzp8k+ /eMVz1w2IMxgp9rUWKkVVRVJzzo/FxwRp0PcJAZNn6YyaG1M10SKE5EjNDTWzJx1FQnn KHEP7TTQOG5nTfMxKcM0Sw6x+3yIqTJPyw0MyxMHYG00peoHZ8M3xl0mEy6/SVGhUagu 8RdpkKDJ7nPIDLM6RAOoRNn2iX1ObQMcfRJhWh1A+hKX1mwReZ/RFGQv1fX2r3M4x/eH ECdw== X-Gm-Message-State: AHQUAub6bm8p/bFZlKlon/Wd3KkQ1UuJsLXHe83YebZgxmKNkltgSpKq s3qA0YZzoBrPUXfBRdbvYg/2nnt/RJ4K7IGGQqfGyt5T0zCjnU0DI0P0PngxHrBKPJ/344JYGNK EIEOW0zhzNVhzy9qH2rg+7h7KZn0aJo9m3VyZ8FmCagzAP3YIAXP7YJ1b/AacGw3qavnTlAUBcv +YArYP+JWb5ZISVk7EiOo3T7GNf8VsB9XghJ6TaPO5WsstVYeo5MD5bAUzngbdPBwhWAOKpHwhY tLFxO409J+Th3HgUmXkIaP//EEVtnme0pI38VHr5j0fdylQ//pGcuZuOesFJa6IoaOTrcKdGDal rv4T60TTgjPMnzueT91VlUIy+EK6u8A3jm7pBe/DI08ArBjjZwJsI63hH8enI6q5k/pmnS/Ylsk F X-Received: by 2002:a17:902:5601:: with SMTP id h1mr722079pli.160.1549304142708; Mon, 04 Feb 2019 10:15:42 -0800 (PST) X-Received: by 2002:a17:902:5601:: with SMTP id h1mr722008pli.160.1549304141919; Mon, 04 Feb 2019 10:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549304141; cv=none; d=google.com; s=arc-20160816; b=IBiQAdfOQTpWl8ZMWfLwckbB2G9rYR9n5Exc9gZ9UDdSCndjkccIuuMmPW2nfdhcql Bi/DWvPBCpaVz8u07ilffDWyPz0xtwHMmKvPA8KnRvN7+hyc+PCDSN5xDSzO7CNMsEx4 MTxxn1XslIrb9EluMoQ0APWBsQso/WCTMe7KDaIvR9HfOe2BSemnG7DBNo+dfdwFmWaM pkXk+EKc/eVISfnM+QG1WbsJh4aRN4lvlGRMt6EoGs0cYwZ0HfEuGKJ7qmRFF8syX3bt n49GPt+SVzzN0F+KDrdO11yHAo4+ljR4ZGxjH0/LHQ/F37v/YIlga7vxbpDKeYP0fVxA 9lOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=zqElbD91wN7xrII3yrqdT2po60YKbiGuJ5EuHOboq08=; b=Gq10teCUIbXBWMSyXYAOdHOpLYFVIyjg1s5kjx+CZwNoMdmuf+PUa8tN7LaIH8yO+y ZVR/JhAbCT2kPzX6WG7+fo6X1AIG1ocW3N4LdY2kWI/C95kTBrabjXh3A7FBcKLoGXvV 2lgTmXj90TpVaJOudKYq35ZolM6A+WGAyPluz3RL7kyYXKP+E/ifeK9Ov94hztKPrFem I9AB/sbA8PR/vBqmxUFtmIYDMJEdTE3CSA7/cA5ALsSqUYD6fmZcdSiS1GG8pusLNJB/ zLOO5d3hVOLMu7tAzyy4w58NUmEaflyxMVtaNUlsCxpEckD0NDnRKOIgpDMumgyCoI9c /ZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oJsYf7z3; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o23sor1340154pgv.0.2019.02.04.10.15.41 for (Google Transport Security); Mon, 04 Feb 2019 10:15:41 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oJsYf7z3; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=zqElbD91wN7xrII3yrqdT2po60YKbiGuJ5EuHOboq08=; b=oJsYf7z38AP8TbCH80dOcCkJYlGDdhpEscQ3nBiPGAezSpQoznfn6yaatFIh56rLa3 WQTC59TkQ38+viuHQYO8ZTHXdI+ikg6haVJUBIfi65J1jh7YFOQScPeFfZn5FdLIwwV1 HQBqxVYcgT/LNtaebjn1fviZ+IgZBpZybIhLxGWy4QMZkk8/ERcgCeCm1h0Ahhp0HBSL ojLR6pytSqLpez0vfIpiHCesbcI1La8NGXWRe7x6NeiEsm8412Xo098elaZawQ0pGk05 5ytGec+2Ioqy0lGzOd4BXBHFOLC6p+IG7quU66Y9Uh+PJMntM5b7DnSKxSFW0Y1aRGXF smjA== X-Google-Smtp-Source: AHgI3Ia491NQopE8fziC0IJZOVG35rTaJ4DGuP8qMsPV/GoMoreeKpaQJ7srkoR5qCHTRvCiosG1aw== X-Received: by 2002:a63:2bc4:: with SMTP id r187mr615506pgr.306.1549304141567; Mon, 04 Feb 2019 10:15:41 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id v89sm1323954pfk.12.2019.02.04.10.15.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 10:15:41 -0800 (PST) Subject: [RFC PATCH 1/4] madvise: Expose ability to set dontneed from kernel From: Alexander Duyck To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: rkrcmar@redhat.com, alexander.h.duyck@linux.intel.com, x86@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, tglx@linutronix.de, akpm@linux-foundation.org Date: Mon, 04 Feb 2019 10:15:40 -0800 Message-ID: <20190204181540.12095.87973.stgit@localhost.localdomain> In-Reply-To: <20190204181118.12095.38300.stgit@localhost.localdomain> References: <20190204181118.12095.38300.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck In order to enable a KVM hypervisor to notify the host that a guest has freed its pages we will need to have a mechanism to update the virtual memory associated with the guest. In order to expose this functionality I am adding a new function do_madvise_dontneed that can be used to indicate a region that a given VM is done with. Signed-off-by: Alexander Duyck --- include/linux/mm.h | 2 ++ mm/madvise.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index e04396375cf9..eb668a5b4b4f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2840,5 +2840,7 @@ static inline bool page_is_guard(struct page *page) static inline void setup_nr_node_ids(void) {} #endif +int do_madvise_dontneed(unsigned long start, size_t len_in); + #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */ diff --git a/mm/madvise.c b/mm/madvise.c index 21a7881a2db4..8730f7e0081a 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -799,7 +799,7 @@ static int madvise_inject_error(int behavior, * -EBADF - map exists, but area maps something that isn't a file. * -EAGAIN - a kernel resource was temporarily unavailable. */ -SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +static int do_madvise(unsigned long start, size_t len_in, int behavior) { unsigned long end, tmp; struct vm_area_struct *vma, *prev; @@ -894,3 +894,14 @@ static int madvise_inject_error(int behavior, return error; } + +SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) +{ + return do_madvise(start, len_in, behavior); +} + +int do_madvise_dontneed(unsigned long start, size_t len_in) +{ + return do_madvise(start, len_in, MADV_DONTNEED); +} +EXPORT_SYMBOL_GPL(do_madvise_dontneed); From patchwork Mon Feb 4 18:15:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10796323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAA8113A4 for ; Mon, 4 Feb 2019 18:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B67D32B720 for ; Mon, 4 Feb 2019 18:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAB622B7F8; Mon, 4 Feb 2019 18:15:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000052B720 for ; Mon, 4 Feb 2019 18:15:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BD7A8E0050; Mon, 4 Feb 2019 13:15:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 070588E001C; Mon, 4 Feb 2019 13:15:50 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9FBE8E0050; Mon, 4 Feb 2019 13:15:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id A59188E001C for ; Mon, 4 Feb 2019 13:15:49 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id y88so494537pfi.9 for ; Mon, 04 Feb 2019 10:15:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=nq0LeNkhaffr3QT/wk9IUrhhpxaGavdHfyKoMsgvjdo=; b=lEsjSoxIL7xTLEfU7JH+Gt/xE5cJaxlcnHok9CP/5Xth1FdA5+lj7kiRzDIjDMbtOr osP7VijmYfVyMuH25xZEivfqtFkV/tlyUV0FKiZhwJpfBoNzwKlkT6mkzyiUCH/OUMrq EbIocBAiMJYB90giI1OlZD3Fw7u9Hmr4vQ5fLs+RmHSEbqDbYwSVB7JCdjtsaSFX/ufw tdIt6Mf3BwM24jBuCem6VGeVxR72s/9UaWVkVnuuTUkXbt8dMDJ4Z8q7vRhpOQ33qrVZ EPSTtoS92P2Ydl7I5B/DaZ7smsTbgMUTjq+7yFeYaKsYUJchAXjUXdULzyQdTtyXcBPt HMGw== X-Gm-Message-State: AHQUAuaTnnP62NoTLod/eIPfm3YtWrFqjBpwvfwCMbyZ8bjnuthQM8Gw N8UEc4sjBLOVNesTFyKtunniw/Mmh1tLBfGyyxH+lcvxH+qufzzbelcUeIQhYxgK4G6JDLCFwpO B/zja6oQ3bVTvoLWa542Po93UyZesVHh31HXQawOkKqi+ykMTn+I4V3/I4axS7MtCdXf6YfcJkz GhW0puCiPJHw2+2zi+iz7zt6cQLxDwvcv7/0ZAb9siBn54/9P1n5lGR4PAw3ij83iRJWXdDhvAD b4bapgXkQNjSlvHv/50ChDbs0gKsifSWFuJlGxWu9XJElvSupiIeusAse8/8u+GkBlHk/2j9Y9y G7T6UlwZVeWtniEsswEtLP7U2vZ7zpniOQKHo0jfcda7LR4rQaOU7eOofwR3fDgXujLVjKfqYBE t X-Received: by 2002:a63:2303:: with SMTP id j3mr583044pgj.391.1549304149247; Mon, 04 Feb 2019 10:15:49 -0800 (PST) X-Received: by 2002:a63:2303:: with SMTP id j3mr582967pgj.391.1549304148192; Mon, 04 Feb 2019 10:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549304148; cv=none; d=google.com; s=arc-20160816; b=igWKkir2XH2YiKYUJkiCml6TYIgB/DHavavEnYkYSm2LXJAELm44hourFId1Qu0Rk0 UneVzoKRy++EoHt5ZF7oOQgbBH2Wgc1kzXB9A18vf7mnrntNpY+ngQVrWPHR++ndGj18 bwGYeZ6TaSlzSiKorAOjZkm16tMavY4Q+3TdIBujayKFLrjtANrl8KhlEeZ4SX7WAYtW OWv5RE0aYRdd3Tav+RAol0Ce6AyF4JjuZJaOnm6/w6QTzY+8ZMBuD97DJvWJsplHQbjK wnusWpPJvwsfV/jJhNClYHqdt5y0Kt49obRZOv91KFIlhDbEUxJy3+nv4LAUSy3xE2eG 1EPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=nq0LeNkhaffr3QT/wk9IUrhhpxaGavdHfyKoMsgvjdo=; b=ohcu0QtTeU+aBm1aqDCWNWqdUH+F86pIo3byNJEKRu3SqwObsFmZu3J6pEy0rXfL2e 6vARF+YJreUw0oCeeEq+zcmAVNZZeu776TuBOGXDYXxYnnPlAZiY8bvWGeps2eMb8LV1 u8RWY++vku/8VhJ2GzbZYWARi8BD1PSd/z5cj/eXCJIZmHwSOabYhkYLhQRdPsPFdmpk VMmZBMvk5n582uIbj+/Ma8on86ch0WZYzEFlvb4w84MBx3n4CvXJ1HanX8ec4Vz5WRpX B2ZvI90OfUq6cAiHw2joGpqm3oOE1SATeDRxrI1UNXqlbxiGcCCXfGTPHcyQBNSx6iv2 Ws9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L7X4qKJ6; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k37sor1311832pgb.78.2019.02.04.10.15.48 for (Google Transport Security); Mon, 04 Feb 2019 10:15:48 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L7X4qKJ6; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=nq0LeNkhaffr3QT/wk9IUrhhpxaGavdHfyKoMsgvjdo=; b=L7X4qKJ6GtgkMcoLCzJQFQp5YQflLDPqBeUBgAQS/WXNVw9NqiYnEdhx6yzV/spFHf 7L6vF0PKeQfrqkdqNkzH3QVdqEBRrkySxTix4y/7CmVOEzkdHP528G8v2K4DbX4S0WV2 AhSF+d4Gsnd8UxoIwWQ8vQD/e9fxTkgZdr562N5/FfkuEGVN08h77ixyK50tK0aEZWUz S3qkPFlc6MIeg2bP73mBpc4Z++3TXyhuw9NU68HOgeGg+81CIb7tNpBUAAWspG1rQu+J wp+8/e5Z5znfNnx7la1axnMHEZ93SPljoKMEtbwXuayDg+bCSFIS50QchxDi7o75IWLR nAKA== X-Google-Smtp-Source: AHgI3IaZMHStqmgitk+Th2B3stPdDyvz8KaztFDV/2BXNVgK22LkFei1Bc7H+nadwdx82aStWOarZQ== X-Received: by 2002:a63:4665:: with SMTP id v37mr575190pgk.425.1549304147758; Mon, 04 Feb 2019 10:15:47 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id x11sm1092934pfe.72.2019.02.04.10.15.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 10:15:47 -0800 (PST) Subject: [RFC PATCH 2/4] kvm: Add host side support for free memory hints From: Alexander Duyck To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: rkrcmar@redhat.com, alexander.h.duyck@linux.intel.com, x86@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, tglx@linutronix.de, akpm@linux-foundation.org Date: Mon, 04 Feb 2019 10:15:46 -0800 Message-ID: <20190204181546.12095.81356.stgit@localhost.localdomain> In-Reply-To: <20190204181118.12095.38300.stgit@localhost.localdomain> References: <20190204181118.12095.38300.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck Add the host side of the KVM memory hinting support. With this we expose a feature bit indicating that the host will pass the messages along to the new madvise function. This functionality is mutually exclusive with device assignment. If a device is assigned we will disable the functionality as it could lead to a potential memory corruption if a device writes to a page after KVM has flagged it as not being used. The logic as it is currently defined limits the hint to only supporting a hugepage or larger notifications. This is meant to help prevent us from potentially breaking up huge pages by hinting that only a portion of the page is not needed. Signed-off-by: Alexander Duyck --- Documentation/virtual/kvm/cpuid.txt | 4 +++ Documentation/virtual/kvm/hypercalls.txt | 14 ++++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 3 +++ arch/x86/kvm/cpuid.c | 6 ++++- arch/x86/kvm/x86.c | 35 ++++++++++++++++++++++++++++++ include/uapi/linux/kvm_para.h | 1 + 6 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt index 97ca1940a0dc..fe3395a58b7e 100644 --- a/Documentation/virtual/kvm/cpuid.txt +++ b/Documentation/virtual/kvm/cpuid.txt @@ -66,6 +66,10 @@ KVM_FEATURE_PV_SEND_IPI || 11 || guest checks this feature bit || || before using paravirtualized || || send IPIs. ------------------------------------------------------------------------------ +KVM_FEATURE_PV_UNUSED_PAGE_HINT || 12 || guest checks this feature bit + || || before using paravirtualized + || || unused page hints. +------------------------------------------------------------------------------ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock. diff --git a/Documentation/virtual/kvm/hypercalls.txt b/Documentation/virtual/kvm/hypercalls.txt index da24c138c8d1..b374678ac1f9 100644 --- a/Documentation/virtual/kvm/hypercalls.txt +++ b/Documentation/virtual/kvm/hypercalls.txt @@ -141,3 +141,17 @@ a0 corresponds to the APIC ID in the third argument (a2), bit 1 corresponds to the APIC ID a2+1, and so on. Returns the number of CPUs to which the IPIs were delivered successfully. + +7. KVM_HC_UNUSED_PAGE_HINT +------------------------ +Architecture: x86 +Status: active +Purpose: Send unused page hint to host + +a0: physical address of region unused, page aligned +a1: size of unused region, page aligned + +The hypercall lets a guest send notifications to the host that it will no +longer be using a given page in memory. Multiple pages can be hinted at by +using the size field to hint that a higher order page is available by +specifying the higher order page size. diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 19980ec1a316..f066c23060df 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -29,6 +29,7 @@ #define KVM_FEATURE_PV_TLB_FLUSH 9 #define KVM_FEATURE_ASYNC_PF_VMEXIT 10 #define KVM_FEATURE_PV_SEND_IPI 11 +#define KVM_FEATURE_PV_UNUSED_PAGE_HINT 12 #define KVM_HINTS_REALTIME 0 @@ -119,4 +120,6 @@ struct kvm_vcpu_pv_apf_data { #define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK #define KVM_PV_EOI_DISABLED 0x0 +#define KVM_PV_UNUSED_PAGE_HINT_MIN_ORDER HUGETLB_PAGE_ORDER + #endif /* _UAPI_ASM_X86_KVM_PARA_H */ diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index bbffa6c54697..b82bcbfbc420 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -136,6 +136,9 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) if (kvm_hlt_in_guest(vcpu->kvm) && best && (best->eax & (1 << KVM_FEATURE_PV_UNHALT))) best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT); + if (kvm_arch_has_assigned_device(vcpu->kvm) && best && + (best->eax & KVM_FEATURE_PV_UNUSED_PAGE_HINT)) + best->eax &= ~(1 << KVM_FEATURE_PV_UNUSED_PAGE_HINT); /* Update physical-address width */ vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); @@ -637,7 +640,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, (1 << KVM_FEATURE_PV_UNHALT) | (1 << KVM_FEATURE_PV_TLB_FLUSH) | (1 << KVM_FEATURE_ASYNC_PF_VMEXIT) | - (1 << KVM_FEATURE_PV_SEND_IPI); + (1 << KVM_FEATURE_PV_SEND_IPI) | + (1 << KVM_FEATURE_PV_UNUSED_PAGE_HINT); if (sched_info_on()) entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3d27206f6c01..3ec75ab849e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -7052,6 +7053,37 @@ void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu) kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu); } +static int kvm_pv_unused_page_hint_op(struct kvm *kvm, gpa_t gpa, size_t len) +{ + unsigned long start; + + /* + * Guarantee the following: + * len meets minimum size + * len is a power of 2 + * gpa is aligned to len + */ + if (len < (PAGE_SIZE << KVM_PV_UNUSED_PAGE_HINT_MIN_ORDER)) + return -KVM_EINVAL; + if (!is_power_of_2(len) || !IS_ALIGNED(gpa, len)) + return -KVM_EINVAL; + + /* + * If a device is assigned we cannot use use madvise as memory + * is shared with the device and could lead to memory corruption + * if the device writes to it after free. + */ + if (kvm_arch_has_assigned_device(kvm)) + return -KVM_EOPNOTSUPP; + + start = gfn_to_hva(kvm, gpa_to_gfn(gpa)); + + if (kvm_is_error_hva(start + len)) + return -KVM_EFAULT; + + return do_madvise_dontneed(start, len); +} + int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) { unsigned long nr, a0, a1, a2, a3, ret; @@ -7098,6 +7130,9 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) case KVM_HC_SEND_IPI: ret = kvm_pv_send_ipi(vcpu->kvm, a0, a1, a2, a3, op_64_bit); break; + case KVM_HC_UNUSED_PAGE_HINT: + ret = kvm_pv_unused_page_hint_op(vcpu->kvm, a0, a1); + break; default: ret = -KVM_ENOSYS; break; diff --git a/include/uapi/linux/kvm_para.h b/include/uapi/linux/kvm_para.h index 6c0ce49931e5..75643b862a4e 100644 --- a/include/uapi/linux/kvm_para.h +++ b/include/uapi/linux/kvm_para.h @@ -28,6 +28,7 @@ #define KVM_HC_MIPS_CONSOLE_OUTPUT 8 #define KVM_HC_CLOCK_PAIRING 9 #define KVM_HC_SEND_IPI 10 +#define KVM_HC_UNUSED_PAGE_HINT 11 /* * hypercalls use architecture specific From patchwork Mon Feb 4 18:15:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10796327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62EE513B4 for ; Mon, 4 Feb 2019 18:15:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 507092B73A for ; Mon, 4 Feb 2019 18:15:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 447032B7F8; Mon, 4 Feb 2019 18:15:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9D752B720 for ; Mon, 4 Feb 2019 18:15:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE23A8E0051; Mon, 4 Feb 2019 13:15:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B91BF8E001C; Mon, 4 Feb 2019 13:15:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA8B78E0051; Mon, 4 Feb 2019 13:15:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 65B428E001C for ; Mon, 4 Feb 2019 13:15:55 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id a23so510252pfo.2 for ; Mon, 04 Feb 2019 10:15:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=YZe004olxwKUVDNhwEwrZ8AUV4iVt97unB7E5kh6nQ4=; b=gIrXvE+myVSPKimzttDGcwbTP+1AWYsE4s83/x5VgqA+S+s0doSW6w0lcnLQ33E0Lz PDOd07TQhn8m2ikOj70IirtiJlneD+bJtLA9DKJ82KV8RH0CB+Dv2rsqW+OOjo8aHkoM EOeY5QKvc40dpn+keL6XAJJlMTs0vBjUMKA7FWJeAKn0nkYFy5k4H7w0LqD42KvoXXbF 87GiJYUOIVh/kn9tzK0tF23WWrnjsCl5GHlfW40R/HrpLWO8dNS/BdirHm1O2sezxDbe Ut/f+Kg+DPgBV/rNGo/w8t0TZFJY0gduWUHBZLggLmQlfmt+pKejO/0HyoYLBssc3mXm 3NsQ== X-Gm-Message-State: AHQUAuaUSEzqwevSrcbR1G4Opt1DEVvOEdwJz8I8y8LnoskKmcKKALaS uzy4eUsLVxpWASfdE5ZtPe2OgPrj/xMiKUdOUqBT35THzPr6DVmGZjrSnVjaoYZayolCAJuttwV 5CR5rwh0w4A3DXCWLF1TSG49qkYiLcGZwBYO8+PbABerwRpxmOz08PFUg8FliftKcsylBk0xg/b z6znCXww85fW/cKiP1WZU35zPWcQiou3K7eFxHoM8en21yq8iTtp7tz8j6iXbWvX4BcDifefavo go//ZZadav8ZpQSA3am62s3I1datAlf6qwZTvEOwKb5VC1/0sRmI7cIDYkcYhifs2cosWf/spOg 0ShEB1QhPij08mHEKXcZ8nhbFf95iTItBsnfwSUvIBgBuzYWN4hebEJI56Q/S1CYIteXTA5+uGC w X-Received: by 2002:a17:902:15a8:: with SMTP id m37mr679178pla.129.1549304155047; Mon, 04 Feb 2019 10:15:55 -0800 (PST) X-Received: by 2002:a17:902:15a8:: with SMTP id m37mr679122pla.129.1549304154269; Mon, 04 Feb 2019 10:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549304154; cv=none; d=google.com; s=arc-20160816; b=JhNaB0ak9BDwcP/dYrPd3McLJmobc94NDLvaoweqOvM70CoduO5avvNLoNILJ18NuJ TVRSKw0Fjh2pidg9rK2M/PdqeqZuRIVCPtH2GErUZlD/CXcahIbP7+PhfAZkyzOCez9j 7b2ZI1WUghA07Gq+E+6okdPwxRs5TC5c9BEB/1B1GMuVH565xAiV8PTfdGQQ5Oj9N/lH Brn2tS2XYmp3moC1d0p292tbomtTrapRDZkcxODlwYdvIDjBbBm0MZGloGxBx6fivSQr Z5efyCdNT5WRzy5qSkwbTqHq4SgsC+j992Cux2k+Uy4F8+OJWRIiooVUtz51U67ksqwE nxjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=YZe004olxwKUVDNhwEwrZ8AUV4iVt97unB7E5kh6nQ4=; b=rGxWDVp7P+PzAx02QxZMD1IiVRcDj8+BYtvyHdL5dceIxLNrNrYZ7K/kcLk+hRLuO3 AkNZLZKzNrrI9qEkGoBk6df+U4DCq83ytClJi33b+QUkOO5SC3OLYTBW/w/vY4jtD92c idU+KYWfLyhdakS5iMSlChRJmwj6ACgNZy/cXfkimIsIYL45hyw1IOSvqb/tHJb2nGok 0VJInQCG5lyjbwXHIy/p5rIeO7sX7lWD7ySdEWmk3FYsRmusW2tr4XlL7lg3ExUI4pTI uAAfVCqFnWKCS0b5ICLMcNGoJ2z2t/BtB/f32G0nB8CS2zxifp4QfNHbvG1GPS3VTqMA u6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IQrmXhYJ; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x5sor1317104pgp.80.2019.02.04.10.15.54 for (Google Transport Security); Mon, 04 Feb 2019 10:15:54 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IQrmXhYJ; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=YZe004olxwKUVDNhwEwrZ8AUV4iVt97unB7E5kh6nQ4=; b=IQrmXhYJn+hqxmnp2CKgxQtlZ/Plcxr3XKvJAlVd5LVl4ehyQEQyTW3i6g9aDkFdWB BlSQvYrHO04cqFRXHDFceoyzCyJjkEUYcdv8SMX3X8kEcAFyGnZZnQy3YTjYAAoKzZzL 37CyqRl4Xz3IG9WZGdn/ub1I0CoSEBtCocL0KPfAtM/Pq8+/TphetVo8ZCIOKRkSMe/e 6zdTFFr4eBZmo16fnkCw3kEFRC29XwHCOtqP8uxcfKFLPIb9OtClIu6+Ed1cZ6kCaIqz YrpTH1YSNpQoSXSdmT38pszxTEWgFqbZ+qx5I7iUCxMXnWy77QKrrIdOErtX/PYZ/ZRv s1xg== X-Google-Smtp-Source: AHgI3IYghO9Gyc5CdVnnZDhQJpFkPxKmWnw3rcVOoUNENx3bnkpWEbZ8P5nJPUmckNTyGdk2ogPr6Q== X-Received: by 2002:a63:1f64:: with SMTP id q36mr580276pgm.230.1549304153874; Mon, 04 Feb 2019 10:15:53 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id q5sm2033090pfi.165.2019.02.04.10.15.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 10:15:53 -0800 (PST) Subject: [RFC PATCH 3/4] kvm: Add guest side support for free memory hints From: Alexander Duyck To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: rkrcmar@redhat.com, alexander.h.duyck@linux.intel.com, x86@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, tglx@linutronix.de, akpm@linux-foundation.org Date: Mon, 04 Feb 2019 10:15:52 -0800 Message-ID: <20190204181552.12095.46287.stgit@localhost.localdomain> In-Reply-To: <20190204181118.12095.38300.stgit@localhost.localdomain> References: <20190204181118.12095.38300.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck Add guest support for providing free memory hints to the KVM hypervisor for freed pages huge TLB size or larger. I am restricting the size to huge TLB order and larger because the hypercalls are too expensive to be performing one per 4K page. Using the huge TLB order became the obvious choice for the order to use as it allows us to avoid fragmentation of higher order memory on the host. I have limited the functionality so that it doesn't work when page poisoning is enabled. I did this because a write to the page after doing an MADV_DONTNEED would effectively negate the hint, so it would be wasting cycles to do so. Signed-off-by: Alexander Duyck --- arch/x86/include/asm/page.h | 13 +++++++++++++ arch/x86/kernel/kvm.c | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 7555b48803a8..4487ad7a3385 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -18,6 +18,19 @@ struct page; +#ifdef CONFIG_KVM_GUEST +#include +extern struct static_key_false pv_free_page_hint_enabled; + +#define HAVE_ARCH_FREE_PAGE +void __arch_free_page(struct page *page, unsigned int order); +static inline void arch_free_page(struct page *page, unsigned int order) +{ + if (static_branch_unlikely(&pv_free_page_hint_enabled)) + __arch_free_page(page, order); +} +#endif + #include extern struct range pfn_mapped[]; extern int nr_pfn_mapped; diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 5c93a65ee1e5..09c91641c36c 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -48,6 +48,7 @@ #include static int kvmapf = 1; +DEFINE_STATIC_KEY_FALSE(pv_free_page_hint_enabled); static int __init parse_no_kvmapf(char *arg) { @@ -648,6 +649,15 @@ static void __init kvm_guest_init(void) if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) apic_set_eoi_write(kvm_guest_apic_eoi_write); + /* + * The free page hinting doesn't add much value if page poisoning + * is enabled. So we only enable the feature if page poisoning is + * no present. + */ + if (!page_poisoning_enabled() && + kvm_para_has_feature(KVM_FEATURE_PV_UNUSED_PAGE_HINT)) + static_branch_enable(&pv_free_page_hint_enabled); + #ifdef CONFIG_SMP smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus; smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; @@ -762,6 +772,19 @@ static __init int kvm_setup_pv_tlb_flush(void) } arch_initcall(kvm_setup_pv_tlb_flush); +void __arch_free_page(struct page *page, unsigned int order) +{ + /* + * Limit hints to blocks no smaller than pageblock in + * size to limit the cost for the hypercalls. + */ + if (order < KVM_PV_UNUSED_PAGE_HINT_MIN_ORDER) + return; + + kvm_hypercall2(KVM_HC_UNUSED_PAGE_HINT, page_to_phys(page), + PAGE_SIZE << order); +} + #ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ From patchwork Mon Feb 4 18:15:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10796331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5EE113A4 for ; Mon, 4 Feb 2019 18:16:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 933D22B720 for ; Mon, 4 Feb 2019 18:16:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 875022B7F8; Mon, 4 Feb 2019 18:16:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F235B2B720 for ; Mon, 4 Feb 2019 18:16:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDCE78E0052; Mon, 4 Feb 2019 13:16:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D8C6D8E001C; Mon, 4 Feb 2019 13:16:01 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA3828E0052; Mon, 4 Feb 2019 13:16:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 86D3A8E001C for ; Mon, 4 Feb 2019 13:16:01 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id f69so505702pff.5 for ; Mon, 04 Feb 2019 10:16:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=BH3kUGOLH4rXiV4UZ/yFSk8Kv2EdG9WZAShG2rqLHTM=; b=LQh9yU4//BZr9AVCcEDPO6wBBstLYo7YQivfNeZe214fIJo4pmTFr7YnQ68E0XWpwE S4uY3g4DYPzpU/ITRsbVs5ek/XzFR7CvtmFtMzBm4W3EgfZ4YSsZu47qxPvnCKJa4D6R lU1oBhyDGMk+NIIYPRTWq/XAf7l/mU6tbBzcew/YPyQQfKWx7TflIV2Bd2LL1fvBT5g/ uNeZXXL7D43VAMEEZ/t+CbKZiMz+CbQDEP6e5+lnB7+Hw3f+OiQK3vG30Qfdm4NYZP7l o9BtchhuZg0KmQwzqyvDrpprLfhRjG7ITIfL5vYuQnv4tVDrfryLtoHjbv2z8N1bs78W G59g== X-Gm-Message-State: AHQUAuYbecBhJRYSlc0EoIqNBvr/yW3ysf4LyNhAkSKllEVrGuFGtE+i gw97FBibNDWWA7i6vdqTlLJXl4YFZkHVAMmQer3+boiJr0vs188+4a+ROJ2rw6vCOfk1QlPAc/l DRlzICFZpqUtdDlrDcPUSottFwDRuuKjYgJOkXeS/mv9LGGfOlt3AvUNai7QsjuylyjFhmO72Lg l/A+lquxmpDcluvIixy0xskgaFfOZrQB5USIWFzXh2Y8eLYqFy3rOsxTryEemmyxBWQjoCLlLuT wVgNqqkwpNJRe+swz58qDNgSWp76KfBhdtDUgcNTsIDUVQx/WhCHq5STIaFyRrxAA4XmVGQIFET qLv5z7N+c95cRc/1bCTVyXZ18bTbBwNV+zgae0hKE+aHNurGTOlUnHxMMrwl+zEU/CM2hA8kx55 1 X-Received: by 2002:a65:4904:: with SMTP id p4mr618141pgs.384.1549304161153; Mon, 04 Feb 2019 10:16:01 -0800 (PST) X-Received: by 2002:a65:4904:: with SMTP id p4mr618085pgs.384.1549304160377; Mon, 04 Feb 2019 10:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549304160; cv=none; d=google.com; s=arc-20160816; b=wYAeOhW00YO05OfQjYZw1XCPpniXjqzeEnv2LtHxsjkef6uM+6WG/zTWHa0CLGT8ei YRm8xFdkLyk/nXSXHQn1GZZ4xBc9rKkv4mhAAXSUOaj+5qdo/xKeXFr8QzfmhS9qyz94 twA39oGC342ETzraN08ElV1msNZ4eo0KyeUn7E/Um+Ias1tg/6dEN4cfyfoAExV+Q0AU PUlmzwCCDuDpHxdvt+FP4/J7gfYBJLAWy1acG9vrDoU+qdSqqFVcxTBK6VN/fryt6O+5 nsbLbbHCDdOfVRszYuUmV86SYmeN2bMuShO1BSJpmQBeoaiXTmmlJd8Ag8nifBBPlxW2 njRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=BH3kUGOLH4rXiV4UZ/yFSk8Kv2EdG9WZAShG2rqLHTM=; b=XmZDpC2zd9DofX4XVr+jUuHiHdJVnhjGl3gj+1uBz0fshZcTswXUgnoCNbA4io34/9 yYT18niLx1ybEU8NDAkHc2cC6OrmXi2/6ycozjy9D++TOc6ux+q2F2KLhlOGL0WuPubh uwphpwPt31hu8L0CyYDe5sX+VSZJaOcJDG50+vr2hgrS9GOYK1SQOxVSXTK9u9dogjVy L/IDh8X1uBRaZxbe4jwlr17sXBwF6Y0jWawRAm2egQzZG1MXJ9nSfvvE5EqeaINLwF78 ybr4ZhHEy559mAG86f5282LAPWGcXXJOU/c1nTUJwz9Ou0IBeWH+Ce9E5doIZCCyT2an IFKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HBVmbsGO; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z1sor1476409pfl.9.2019.02.04.10.16.00 for (Google Transport Security); Mon, 04 Feb 2019 10:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HBVmbsGO; spf=pass (google.com: domain of alexander.duyck@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=alexander.duyck@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=BH3kUGOLH4rXiV4UZ/yFSk8Kv2EdG9WZAShG2rqLHTM=; b=HBVmbsGODWcw1Zzq6loJb9qa/nqzCqIjc1caWDwzjyVMZ0cmFJhvTchZVI2WOq0SGD K4mHhjv+oZT7Dk4YHXIh0FzSfuUvWLrG1BGCDIpuHv+axbdWqQYThhkdY5vAh6CubTRI 6G4HgTpmqZTTI1aEb1ZK3zYjOIvHQ9+xhErmeERXv3lpM/Hbv04CdXW8ILjza6RN2IJa q+7M7+iRHnlW3ZY88/DcYz7Uy5sz23/8oKf6rqSooCtg8X23HxZJlCOC3paGvl4fG0eN amSuhIznkGkG7AuuxMuc46cqDxIP0uc2r4qUVRoHCp5Qyz4dV046yyikJ4zcIEwnzJH3 XWKA== X-Google-Smtp-Source: AHgI3IatDmHCVIQvkPjf403DPZXddCGM1dtT3pI76p0hmmxOMfvPU6zQrFp/JIlwwbmQbdyNZzEbOA== X-Received: by 2002:a62:37c3:: with SMTP id e186mr635900pfa.251.1549304159979; Mon, 04 Feb 2019 10:15:59 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id d129sm991541pfc.31.2019.02.04.10.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 10:15:59 -0800 (PST) Subject: [RFC PATCH 4/4] mm: Add merge page notifier From: Alexander Duyck To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: rkrcmar@redhat.com, alexander.h.duyck@linux.intel.com, x86@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, tglx@linutronix.de, akpm@linux-foundation.org Date: Mon, 04 Feb 2019 10:15:58 -0800 Message-ID: <20190204181558.12095.83484.stgit@localhost.localdomain> In-Reply-To: <20190204181118.12095.38300.stgit@localhost.localdomain> References: <20190204181118.12095.38300.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck Because the implementation was limiting itself to only providing hints on pages huge TLB order sized or larger we introduced the possibility for free pages to slip past us because they are freed as something less then huge TLB in size and aggregated with buddies later. To address that I am adding a new call arch_merge_page which is called after __free_one_page has merged a pair of pages to create a higher order page. By doing this I am able to fill the gap and provide full coverage for all of the pages huge TLB order or larger. Signed-off-by: Alexander Duyck --- arch/x86/include/asm/page.h | 12 ++++++++++++ arch/x86/kernel/kvm.c | 28 ++++++++++++++++++++++++++++ include/linux/gfp.h | 4 ++++ mm/page_alloc.c | 2 ++ 4 files changed, 46 insertions(+) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 4487ad7a3385..9540a97c9997 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -29,6 +29,18 @@ static inline void arch_free_page(struct page *page, unsigned int order) if (static_branch_unlikely(&pv_free_page_hint_enabled)) __arch_free_page(page, order); } + +struct zone; + +#define HAVE_ARCH_MERGE_PAGE +void __arch_merge_page(struct zone *zone, struct page *page, + unsigned int order); +static inline void arch_merge_page(struct zone *zone, struct page *page, + unsigned int order) +{ + if (static_branch_unlikely(&pv_free_page_hint_enabled)) + __arch_merge_page(zone, page, order); +} #endif #include diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 09c91641c36c..957bb4f427bb 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -785,6 +785,34 @@ void __arch_free_page(struct page *page, unsigned int order) PAGE_SIZE << order); } +void __arch_merge_page(struct zone *zone, struct page *page, + unsigned int order) +{ + /* + * The merging logic has merged a set of buddies up to the + * KVM_PV_UNUSED_PAGE_HINT_MIN_ORDER. Since that is the case, take + * advantage of this moment to notify the hypervisor of the free + * memory. + */ + if (order != KVM_PV_UNUSED_PAGE_HINT_MIN_ORDER) + return; + + /* + * Drop zone lock while processing the hypercall. This + * should be safe as the page has not yet been added + * to the buddy list as of yet and all the pages that + * were merged have had their buddy/guard flags cleared + * and their order reset to 0. + */ + spin_unlock(&zone->lock); + + kvm_hypercall2(KVM_HC_UNUSED_PAGE_HINT, page_to_phys(page), + PAGE_SIZE << order); + + /* reacquire lock and resume freeing memory */ + spin_lock(&zone->lock); +} + #ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ diff --git a/include/linux/gfp.h b/include/linux/gfp.h index fdab7de7490d..4746d5560193 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -459,6 +459,10 @@ static inline struct zonelist *node_zonelist(int nid, gfp_t flags) #ifndef HAVE_ARCH_FREE_PAGE static inline void arch_free_page(struct page *page, int order) { } #endif +#ifndef HAVE_ARCH_MERGE_PAGE +static inline void +arch_merge_page(struct zone *zone, struct page *page, int order) { } +#endif #ifndef HAVE_ARCH_ALLOC_PAGE static inline void arch_alloc_page(struct page *page, int order) { } #endif diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c954f8c1fbc4..7a1309b0b7c5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -913,6 +913,8 @@ static inline void __free_one_page(struct page *page, page = page + (combined_pfn - pfn); pfn = combined_pfn; order++; + + arch_merge_page(zone, page, order); } if (max_order < MAX_ORDER) { /* If we are here, it means order is >= pageblock_order.