Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5818499rwp; Mon, 17 Jul 2023 09:53:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlE0s60AxwtNe2xAvraKxxgI4rWmLa0DPX9V8aR9i2SowwXnwsc2AD8vmwePbGAQ9dmgmO3G X-Received: by 2002:a05:6a00:ad1:b0:67d:22a6:2f54 with SMTP id c17-20020a056a000ad100b0067d22a62f54mr5945pfl.31.1689612826055; Mon, 17 Jul 2023 09:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689612826; cv=none; d=google.com; s=arc-20160816; b=nfl1rYjGqcdYEy4u5XNZaJ+r4tzwAhbTzAF0GEwVGvtc83u8M60QT6/M0nTFZL9rfw ItiY00LzwRhCSjyhM0NpT0modL7/b8TeqCxcSH3g0jriCTBOO6pVEQ3lLbjWmSTWzdvS xL7DkipurH+Uw20dhG3HoNrVOZDmNIXX6RbyBwzhadO6xfJ9OULkpVtjJ5ezl9DWZFrn +aD+W8IeF80PwummXCkJYnkSdMcVKFqMzKFT4SIQ2XV9+HMVcKxaqjdUteGeSXlU+dDH rnqer2kBBj1nVWpI5uxnvr7tpE8kowfiiZI75uTn7N/fIwc6UhmmyU0o9YGNlVhVKEP8 8BAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=XY4N++ouOf9JpbfnfTNhYe0rv+OT6iZb3HZAx55/hBE=; fh=HKwfxB1+rp/u5yhWj3eSr2ACYg+d50DkNtm54JaYY9s=; b=oYUzxA8XKubf3M4fkQL7PoyFVSz4txRQVDtFs4l6w306fnxTxPMCaNpd+oL3SZMBad mGc0J20Y7IAboZsPsbk711fxVZ9tg1w3VHsR92hjT9/nJiAexf2xqQzPmvDJWg9fMrcR jebHnKNbH9CHsrA6OjO8ZGv3LieFVhlQ3cdtEMsT1o2zzpPEAecDmVTS6kAMmHglJ63+ 0jgU+6emrRzDQW/7L9SWuZePiBI+z8FLpMwzBgWjU/oWTjGxYsxnhnFwzI1g2AgtDCEa exP0RvZM327/1rm/fxWfiKW7+WY58evTJSQeExsxEBkjE5eaIaRuSsGq/P43PXw6w+Yl sOqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=qDsWDanx; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=mItGbQH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw17-20020a056a00369100b0064d28b68d8fsi56150pfb.94.2023.07.17.09.53.33; Mon, 17 Jul 2023 09:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=qDsWDanx; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=mItGbQH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjGQQTY (ORCPT + 99 others); Mon, 17 Jul 2023 12:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjGQQTW (ORCPT ); Mon, 17 Jul 2023 12:19:22 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB46129 for ; Mon, 17 Jul 2023 09:19:20 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 19A841FDAC; Mon, 17 Jul 2023 16:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1689610759; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XY4N++ouOf9JpbfnfTNhYe0rv+OT6iZb3HZAx55/hBE=; b=qDsWDanx+QjaC0M9RCXYHIW0xMtOSLY67aiwJTsEgCDecPZrpOZ62iMYESeuhl/VlhXvC2 cFkTPFG9OSwu1gBpHlUn4gqHBAUzHcd8bSDPkCEXcxhtpao8/hpXem1oK0N0+J7VI9D+Ni DWrz78xlQcdTkrKhFZNATX7YmMja+FI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1689610759; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XY4N++ouOf9JpbfnfTNhYe0rv+OT6iZb3HZAx55/hBE=; b=mItGbQH1Q2d/vyi5aOfJG/V0uj7yIrvvBTv20aHMiBPE46bArtzpdCHdntMcnU93lKhcLZ AvbRZCHHZfJ8n0Bw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D045B138F8; Mon, 17 Jul 2023 16:19:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yh55MQZqtWSdJwAAMHmgww (envelope-from ); Mon, 17 Jul 2023 16:19:18 +0000 Message-ID: <399a6448-184b-1433-3f23-1a599656a713@suse.cz> Date: Mon, 17 Jul 2023 18:19:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: mprotect and hugetlb mappings Content-Language: en-US To: Mike Kravetz , Matthew Wilcox Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand , Rik van Riel , Michal Hocko , Peter Xu , Dave Hansen References: <20230705230808.GA41006@monkey> <20230705235322.GD41006@monkey> From: Vlastimil Babka In-Reply-To: <20230705235322.GD41006@monkey> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/6/23 01:53, Mike Kravetz wrote: > On 07/06/23 00:22, Matthew Wilcox wrote: >> On Wed, Jul 05, 2023 at 04:08:08PM -0700, Mike Kravetz wrote: >> > I was recently asked about the behavior of mprotect on a hugetlb >> > mapping where addr or addr+len is not hugetlb page size aligned. As >> > one might expect, EINVAL is returned in such cases. However, the man >> > page makes no mention of alignment requirements for hugetlb mappings. >> > >> > I am happy to submit man page updates if people agree this is the correct >> > behavior. We might even want to check alignment earlier in the code >> > path as we fail when trying to split the vma today. >> > >> > An alternative behavior would be to operate on whole hugetlb pages within >> > the range addr - addr+len. >> >> After a careful re-reading of the mprotect() man page, I suggest the >> following behaviour ... >> >> addr must be a multiple of the hpage size. Otherwise -EINVAL. >> len should be rounded up to hpage size. >> >> I wonder how likely this change would be to break userspace code. >> Maybe some test cases. > > My concern is that this is the approach I took with huegtlb MADV_DONTNEED, > and this caused problems discussed and eventually modified here: > https://lore.kernel.org/linux-mm/20221021154546.57df96db@imladris.surriel.com/ > > In the MADV_DONTNEED case we were throwing away data. With mprotect we are > only modifying access to data. That can still confuse some userspace, no? I think realistically we can only document the current implementation better, maybe improve it without changing observed behavior as you suggested wrt the split vma fail. But changing it would be dangerous.