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 5979DC433EF for ; Thu, 13 Jan 2022 16:48:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2B006B0071; Thu, 13 Jan 2022 11:48:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB3A66B0073; Thu, 13 Jan 2022 11:48:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2D216B0074; Thu, 13 Jan 2022 11:48:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id 915396B0071 for ; Thu, 13 Jan 2022 11:48:55 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 568A88A9A6 for ; Thu, 13 Jan 2022 16:48:55 +0000 (UTC) X-FDA: 79025848230.10.60724C4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id D53FE1C0002 for ; Thu, 13 Jan 2022 16:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642092534; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4CP8RXj45JsrXKvLXobja12t+tuHF1y1kRh+2Obu+Fs=; b=RfO4R6S1sIQJ/DYzaS+KIYT/uVYjU2UPu+3ZOy0ZZv0Lq2JUel02NDol6YUNI3ChHSYo1d WkOi6etAbQB8TSLwj+hEz28brDsFwHF/Cy3eoxwrn5Nh+xmnx+9nkBm9ZabkBRKOLV52av ZwFYKG/vnXygbKdA7yTJ3qDz12Q4TpQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-2-JzNXtzOuCxfDs0UOnRSQ-1; Thu, 13 Jan 2022 11:48:52 -0500 X-MC-Unique: 2-JzNXtzOuCxfDs0UOnRSQ-1 Received: by mail-ed1-f70.google.com with SMTP id y18-20020a056402271200b003fa16a5debcso5877571edd.14 for ; Thu, 13 Jan 2022 08:48:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=4CP8RXj45JsrXKvLXobja12t+tuHF1y1kRh+2Obu+Fs=; b=wuI8g78dSI/hUJd7y6vMwgs3v1kGPvO3/kECiU8y5G41WFlZW6dFsGtBkUhQg7PUnS c4d7QW/n4ozeLxDtoCSUTShgWyzP9Cx921QPAet5TaQJm2FT627cbp9YC/4tVuTBG7Tf zEt+rxwMdt3rPX6wl3CrpYilV0AAxVQMcFStzAcidMZhtEZmWKEByEfBVGgjSLUziNvb 6bJcLhxRFDj658/dBUuQhY4bxlxV3j1ylPgE9cv8HFe6I1IU4zGfoXIVQv4ro5CDf1Uf TXS11Bkj9FfPQqnJAtGHrpPuVxSxpMpWErcKE77AimFrQu4aaNQvQlWe0Yl8EyfZH20k q8rg== X-Gm-Message-State: AOAM530UqrW1nmJeHp1/4VMF+C+nPG38SwDkabCBftMgrLM805ehh+Rb 0pg9OiMHC/Q+K6x2c7jyjX46EBxIz2g8sAx4VA57R3pbW0X5QMhC+mzA8mZal4hABzmUvT7MGgr u1ta8u9VfKh8= X-Received: by 2002:aa7:c7cf:: with SMTP id o15mr5019214eds.176.1642092530985; Thu, 13 Jan 2022 08:48:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/vRcGkOKmm25+gp3DEhhhNaMEVPYdtS7M1Nxz5zxBCvTUiLiq6IyZ0Ch0q2yCk1Lm/iQpPw== X-Received: by 2002:aa7:c7cf:: with SMTP id o15mr5019199eds.176.1642092530810; Thu, 13 Jan 2022 08:48:50 -0800 (PST) Received: from ?IPV6:2003:cb:c703:e200:8511:ed0f:ac2c:42f7? (p200300cbc703e2008511ed0fac2c42f7.dip0.t-ipconnect.de. [2003:cb:c703:e200:8511:ed0f:ac2c:42f7]) by smtp.gmail.com with ESMTPSA id hq35sm1039972ejc.54.2022.01.13.08.48.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 08:48:50 -0800 (PST) Message-ID: <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> Date: Thu, 13 Jan 2022 17:48:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 To: Linus Torvalds , Matthew Wilcox Cc: Liang Zhang , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com References: <20220113140318.11117-1-zhangliang5@huawei.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D53FE1C0002 X-Stat-Signature: psqd5sp67i1ce5153qnaxs81b3bi6fsa Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RfO4R6S1; spf=none (imf21.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1642092534-563827 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: On 13.01.22 17:37, Linus Torvalds wrote: > On Thu, Jan 13, 2022 at 6:39 AM Matthew Wilcox wrote: >> >> Let's bring Linus in on this, but I think this reintroduces all of the >> mapcount problems that we've been discussing recently. >> >> How about this as an alternative? > > No, at that point reuse_swap_page() is the better thing to do. > > Don't play games with page_count() (or even worse games with > swap_count). The page count is only stable if it's 1. Any other value > means that it can fluctuate due to concurrent lookups, some of which > can be done locklessly under RCU. I'm pretty sure the patch as is will reintroduce the CVE. So I think in addition to the reuse_swap_page() check we need more. I'm wondering if we can get rid of the mapcount checks in reuse_swap_page() and instead check for page_count() and swapcount only. We don't care if it's unstable in a sense than it will be bigger than what we expect. In that case we COW as we would already do. Thoughts? -- Thanks, David / dhildenb