From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCB20C54EBC for ; Sun, 8 Jan 2023 23:34:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C94868E0002; Sun, 8 Jan 2023 18:34:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C44C18E0001; Sun, 8 Jan 2023 18:34:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0C5B8E0002; Sun, 8 Jan 2023 18:34:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A225E8E0001 for ; Sun, 8 Jan 2023 18:34:56 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 75F0BA01C7 for ; Sun, 8 Jan 2023 23:34:56 +0000 (UTC) X-FDA: 80333239392.15.0BD8671 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf29.hostedemail.com (Postfix) with ESMTP id D084D120003 for ; Sun, 8 Jan 2023 23:34:52 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Y57NbzzQ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673220894; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ADwdCgnn0oisCj+AsLaBYldca4YikYhZ3MCnSz9ePaU=; b=djPAiN99ii2wo2xV/gYYWSpzozIJL43mtUcZ9VZjopTZWlGNIpkZj46E1HGgTQsuUZA5vK rp7Gkj+KgNzS6cDHR6cbKGuTAbSGM6r6+4T5nv86cPcadGTerphnPX8ktBKGqEu6msz3v1 uPfmnptphTFhn8xcudpTNYpqMt7Q5Cg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Y57NbzzQ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673220894; a=rsa-sha256; cv=none; b=S3YeXjxLjheN7ov2EYk+kTI912riN5+l/N+PnyASXmoYj2l+eO5vlOUEP9a4t2FZKW2+7s 8zN254l71bAbuI8B9zOrtbZMCXbNAdSBDyAaVqtu2TIlTDDzKfkLlYvIcx13m/BuB5+ybB XoxV8zEfOYr14c8B8EKRjywrVX91BLU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673220893; x=1704756893; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=oBpAHHXmTGDsYovXPRtYJAb4yr2fncmWitZMe1N0bmE=; b=Y57NbzzQpD4QhOctlHyeyXewpwqsSTNO4tfn+vLZRx56Fh40xgYJBX1p UT6oW6B8PIoSus/F1HiIZN3yzlDO/ckWzEOz7R6oF4I+8y/0/oFxqPBPT jcicyK/2+mz5+OIjCcHTn+zzI74JDMmlVPP9zRvq4B41DkpkqzNROq9Y/ Lb8nN3jBTS9oi0i6hjda8HxVCaRLwPtv+JvwIpt+jSI66gMqpmLQJ5DPc A8NWeCsr1LWzJlxJW9p8ppRsP40JoXyYFKoo4zf/mU1bLNpSZFcbKslVV XjT0RzjkcMKufZ6q2nESuqI/7tUZWEDsASUZjBhsKg/mMZgL6wKFjKKka g==; X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="321468321" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="321468321" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 15:34:50 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="634026795" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="634026795" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 15:34:46 -0800 From: "Huang, Ying" To: Kees Cook Cc: Nathan Chancellor , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin Subject: Re: [PATCH 4/8] migrate_pages: split unmap_and_move() to _unmap() and _move() References: <20221227002859.27740-1-ying.huang@intel.com> <20221227002859.27740-5-ying.huang@intel.com> <202301051056.9D8CB1C24@keescook> Date: Mon, 09 Jan 2023 07:33:45 +0800 In-Reply-To: <202301051056.9D8CB1C24@keescook> (Kees Cook's message of "Thu, 5 Jan 2023 10:57:16 -0800") Message-ID: <87pmbo7g9y.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D084D120003 X-Stat-Signature: gwomohsd3u19c44g96phjf8ksbjwb5fb X-HE-Tag: 1673220892-647129 X-HE-Meta: U2FsdGVkX1+5CiEjpUF/Tpds9LnVkdybTkuc0BGEpuz51yHgu6l/Qhu73+Bv2GnQ/UA8NPR+AZT7TzS3lRWCit3RsYY1OFKGz+K//GlpQ00Zfe+6EQbVW43qxLIl/DiDZM70oaKWiXoKEnd+uKUW8PI/1xIN3o/OPXlzp3vcArwSlqweqZaVicpN66Yo+zGGMCEOVTqub2bJm1n9Bsk7pySq8rR0C1ohs8geubQ0ZPFXb8iH62xCKmZ54WHFakksIbl0yZfh9eon9daO8bACOdVy1pOo6qxd4vofjOlVq6Y4F51hAa3kPhl55fcub3poR9CHSGY3nHUowyUzhyVdyGBLciBcpQma3jkQyuB55iqrUL8QNbOeVqYVSOdaaiQennJVreCNOSkERmRSBzyEDoB38gv/8fu+pah1xXpfNXM9ZbzPLB/4EySj0HxVUWoH14s/K9b1JMQ2LyzTO3JheBY8IBzEPYMuBxvPxf8yHKUcbkKWL0IqQCQuLRV4tbchg0eV2eYQNcy6MS0pqEPEiTPN/PRs38B2KRSfMKOqqnziTauniOqc6eJwmS3UEo5UVGAa71y+N9nfJr5Tg6EZTs6yPp0b0wYqPKx9U/ik9qIRf2+gYm+7TTqMnOGemb+x+4TqEiolbcU6oJV5QzeKPVyS7CG3Ne0kt2LhLPcqeEypHdp8MXUl6bqy/t4a9PfJRwzRoQbJ+prnAfMq+UXo9dyKBIpNyXCOh4ejBn7wqCgEdWGkylqMc19gL2WIpUHmZGSzeSB57NHJ8VRnd/yQBR+gMk864IvL6En499SA7dbuej2OAsu6urCNBvK4Vn/bqvjayTK1DHp5yboJgteWfd/X/98E3e6ZB3JgkMB6iwAGeuG+oZpoLwdPpjyAtNkd1DKxyZuW7REG5r1LBGIudK79IihjUgKt 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: Kees Cook writes: > On Thu, Jan 05, 2023 at 11:26:55AM -0700, Nathan Chancellor wrote: >> Hi Ying, >> >> On Tue, Dec 27, 2022 at 08:28:55AM +0800, Huang Ying wrote: >> > This is a preparation patch to batch the folio unmapping and moving. >> > >> > In this patch, unmap_and_move() is split to migrate_folio_unmap() and >> > migrate_folio_move(). So, we can batch _unmap() and _move() in >> > different loops later. To pass some information between unmap and >> > move, the original unused dst->mapping and dst->private are used. >> > >> > Signed-off-by: "Huang, Ying" >> > Cc: Zi Yan >> > Cc: Yang Shi >> > Cc: Baolin Wang >> > Cc: Oscar Salvador >> > Cc: Matthew Wilcox >> > Cc: Bharata B Rao >> > Cc: Alistair Popple >> > Cc: haoxin >> > --- >> > include/linux/migrate.h | 1 + >> > mm/migrate.c | 162 +++++++++++++++++++++++++++++----------- >> > 2 files changed, 121 insertions(+), 42 deletions(-) >> > >> > diff --git a/include/linux/migrate.h b/include/linux/migrate.h >> > index 3ef77f52a4f0..7376074f2e1e 100644 >> > --- a/include/linux/migrate.h >> > +++ b/include/linux/migrate.h >> > @@ -18,6 +18,7 @@ struct migration_target_control; >> > * - zero on page migration success; >> > */ >> > #define MIGRATEPAGE_SUCCESS 0 >> > +#define MIGRATEPAGE_UNMAP 1 >> > >> > /** >> > * struct movable_operations - Driver page migration >> > diff --git a/mm/migrate.c b/mm/migrate.c >> > index 97ea0737ab2b..e2383b430932 100644 >> > --- a/mm/migrate.c >> > +++ b/mm/migrate.c >> > @@ -1009,11 +1009,29 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, >> > return rc; >> > } >> > >> > -static int __unmap_and_move(struct folio *src, struct folio *dst, >> > +static void __migrate_folio_record(struct folio *dst, >> > + unsigned long page_was_mapped, >> > + struct anon_vma *anon_vma) >> > +{ >> > + dst->mapping = (struct address_space *)anon_vma; >> > + dst->private = (void *)page_was_mapped; >> > +} >> > + >> > +static void __migrate_folio_extract(struct folio *dst, >> > + int *page_was_mappedp, >> > + struct anon_vma **anon_vmap) >> > +{ >> > + *anon_vmap = (struct anon_vma *)dst->mapping; >> > + *page_was_mappedp = (unsigned long)dst->private; >> > + dst->mapping = NULL; >> > + dst->private = NULL; >> > +} >> >> This patch as commit 42871c600cad ("migrate_pages: split >> unmap_and_move() to _unmap() and _move()") in next-20230105 causes the >> following error with clang when CONFIG_RANDSTRUCT is enabled, which is >> the case with allmodconfig: >> >> ../mm/migrate.c:1041:15: error: casting from randomized structure pointer type 'struct address_space *' to 'struct anon_vma *' >> *anon_vmap = (struct anon_vma *)dst->mapping; >> ^ >> 1 error generated. >> >> With GCC, there is only a note: >> >> ../mm/migrate.c: In function '__migrate_folio_extract': >> ../mm/migrate.c:1041:20: note: randstruct: casting between randomized structure pointer types (ssa): 'struct anon_vma' and 'struct address_space' >> >> 1041 | *anon_vmap = (struct anon_vma *)dst->mapping; >> | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> Kees has done fixes for warnings and errors like this in the past (I >> just ran >> >> $ git log -p --grep='randomized structure pointer type' >> >> to find them) but I did not see any that would seem appropriate here >> hence just the report :) > > If this struct is literally just a scratch space and the original struct > layout doesn't matter, it may be possible to silence this cast by using > "(void *)" instead of the explicit struct type pointer. It works! Thank you very much! Best Regards, Huang, Ying