From patchwork Sun Nov 19 19:47:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460675 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 79574C072A2 for ; Sun, 19 Nov 2023 19:49:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0500F6B03BF; Sun, 19 Nov 2023 14:49:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F40966B03C6; Sun, 19 Nov 2023 14:49:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D93AF6B03CA; Sun, 19 Nov 2023 14:49:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C49836B03BF for ; Sun, 19 Nov 2023 14:49:06 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A74F91CAF4D for ; Sun, 19 Nov 2023 19:49:06 +0000 (UTC) X-FDA: 81475742292.27.C5C9162 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf26.hostedemail.com (Postfix) with ESMTP id D763F140014 for ; Sun, 19 Nov 2023 19:49:04 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IeFcDWJH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700423344; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; b=DsJArpAM88Tnt4jDis4JIs0/BrG610iW/zbclpBOe72DU8p2gGlxbKiBf9b7WlzQiBz5/B eXy1HZyTeGaFZ0p/MWYKRa8LQUyeKUvFLbQX316SFhESfmAVbfzaO3cqVuLe8v29li/shC NOiOik3lbvd6+wbOkWuAGNdv2PFL5MY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IeFcDWJH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423344; a=rsa-sha256; cv=none; b=Nx6jcTZ2kRy/odI4Ss+B8mW21E1lYDR2UMU4/4gf0FekjpWQzbHaypjCvfecI63cnScDFZ P3D3FYPyObaQlIxbYcmwSZFsyHZLtbdfnhbIBTfyxF3t0eOOFnm00PeGC9cVqRj6l4nKKj H1oGGsiI+fU10J2owjL6sHd5nltIVeY= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6b7f0170d7bso3605658b3a.2 for ; Sun, 19 Nov 2023 11:49:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423343; x=1701028143; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; b=IeFcDWJHKFixFZKnGcZKlveIDvC1LIocxukfp7I0FCFUA34bOHj9RlAQL8q5azxHf8 irgbwD4YhHThG0I3hlCtAdkO604Bomaj1oJydYkzwBvVCmaasBHrqCbdDawXsulpe6/n CyhPdlZapKQ3cXWuvSrl5s9kZ7NkEdU21eVs2GluvzTMwv/KE4yReZ4mi6synsXaAb6T tusLR6pLyDLvCYhkYFB44gfASSMmqSm+6mdj15pd3saWb1gyBLuvrUOPBKOhFt5ekx2G RCRq6LIfSdjXJNLUuRlV6geEo9OHLSlsNCsQpAFsYPVX/zaQYxAcVRFWcTV1LH6plJMu Vi6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423343; x=1701028143; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; b=dinXHl5+uqkEuSRj7mEyJsZEK0s+F7gSxTs2ByQwxfYljjMVQEonFU4FQZLPKdzhjY 0ysuCXDmfsnH6h/KDBT7TG3IzclO5HWIu+Q0rDmqaBNKJZfd4KXmh8Vq4dBRDUdGZoxN FTqNcrQ/9Q9cC1k4tZSbXr9/U3tMrrgUSw8CBzmyl5+Ke7479/iNT4Ze48J7kOi+Tv2Z 9XOY9nZDJndHTuddQDfXMueJB6sxZ+mhOzmRk7pJinRhxUzNznZjaUCAjC8qVUiMIB1R F4NyLUqoddz2R8oVJ01o+TYfvPo0Inmlm1HiCBIICyXR3BwRFU8JnsaLEWqR52fLN9De fNrQ== X-Gm-Message-State: AOJu0YyrFvfR2GMsLclReO1Hj3EGrtnd72LGwQgQ23igWuJnYC4zza/I o4AgDp4LqmHXI6mwVM6PWDRt7wiw0ZjzQNN3 X-Google-Smtp-Source: AGHT+IGkCTfkx1rp2FzBZeJz7DuMjH5OX9xB0kVWtfaGQTv9o7aHxqdL3R9OOEYrRIDUL1WVW8rBzw== X-Received: by 2002:a05:6a20:748e:b0:186:58d6:ca65 with SMTP id p14-20020a056a20748e00b0018658d6ca65mr7241893pzd.32.1700423343119; Sun, 19 Nov 2023 11:49:03 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.49.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:49:02 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 19/24] shmem, swap: refactor error check on OOM or race Date: Mon, 20 Nov 2023 03:47:35 +0800 Message-ID: <20231119194740.94101-20-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: qb7yjnf5fd8w6azq9gq888ted8gk6g88 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D763F140014 X-HE-Tag: 1700423344-910708 X-HE-Meta: U2FsdGVkX1/je2Sk1VApub/RT+07Kp0a2alR/gRg+kLxc80XwuWw+mQxYJvFvLL1aRrUm9fEZYMmUqS27jAWPpAo55mevdsgJGr+AAQF4tyNoNxEpiuuCVeZHJSv5TSB27H/WLbhtf4tLWI4Jeq4F7bMaV3XDD2fXBniPAB5rLH2pMRgjHG9y4zFlJ4bZx7cocj7N+rSq5LaGCbQ61FW4qbJwsgnDbCyxvmG/ONgrYzOlqoiwh44dx40L1IkPpStOZWr5WHJ3IGHKRrhvFucc+/0CANerNXagdOaL9qnIiZf6UZ7Uh6lZObysDmfMK9A1h1/1uaJVYqmQrec1Gk5UqJr7uGd+icGNGwKap90fAtxjOmyB5mw0ICJlfwFZH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/2LqXz5WWMMumTVUvR0hlTFmfhzmvoPVjC38Fv5cSIWD5732ZROcxf6ZrXjQDy8gYN9Bbw/bSm0Xy+5zho6vF3eUpday2kTitEd5x5Cl1WPCt8Tchs6+PYAE4L1sx9ezALp31aOrYf8dEWDwSjqIMA6Zav333JA0/cQ7vOb9m2bsWe3wlmymqyQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song It should always check if a swap entry is already swaped in on error, fix potential false error issue. Signed-off-by: Kairui Song --- mm/shmem.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 81d129aa66d1..6154b5b68b8f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1857,13 +1857,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, page = swapin_page_non_fault(swap, gfp, mpol, ilx, fault_mm, &result); mpol_cond_put(mpol); - if (PTR_ERR(page) == -EBUSY) { - if (!shmem_confirm_swap(mapping, index, swap)) - return -EEXIST; + if (IS_ERR_OR_NULL(page)) { + if (!page) + error = -ENOMEM; else - return -EINVAL; - } else if (!page) { - error = -ENOMEM; + error = -EINVAL; goto failed; } else { folio = page_folio(page);