Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1822543rdb; Sun, 19 Nov 2023 11:50:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7YfVYtHln9sWDofjwNYX2tYKTyVDXdGsJ6iceTBx4igEWGOxINX5geOnZh6RHZsqdeNPN X-Received: by 2002:a05:6a20:3ca4:b0:17e:70fa:3f3c with SMTP id b36-20020a056a203ca400b0017e70fa3f3cmr7018475pzj.57.1700423438235; Sun, 19 Nov 2023 11:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700423438; cv=none; d=google.com; s=arc-20160816; b=UBB/skH/ExolO7d7uB18TDLr7p9Yr0TPEpgsa3MBJwb/lb5h6LIRwC2zzA8Zad4fsn vjfdCipgmmmM0r3Fa4T1sx6CJzJgZVuinmpaX2nHMJBs79IwDH8fFRPmXna0EE5p3QAa QDTpNx/1wpqSb4Ar/iISvKNSJEDw/HYomjRyNDPeBvv7NfMTp5TFnj17wmzaJLIBUVC1 C91OhdNzVvFU8/xMJp/KbnALyqM2j4eiJ/8gnDH6JyIy2BaYDzKjNrWrfngIOZS2KY1K cMUZVqbIAf6B0EYQinjjo8c7dSfw2qAa6toOLB6G/4Q2Q/W8iOd0Olqh+xR+LrlGg0lF COqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CM+OPz8sAX9/+pckE36Q2lCrK7XvSIfXWi261rZELtQ=; fh=4HE/piJoUCKuBTCCBiej4//zvvzywHdOLL9QM/KYjYM=; b=mBppBNjSJR6mEU8r8kjPlSGF3LZaRY+nSl3Q/x/CYA6iHzeB8rWCUBGah6fZu4B17p x6HFJmxLYRAooBGWSbkq5C1KE0uYTpy+fhwT/Ok8eKTQwCNwTq4EF69wcb3dQ/DO4V8p YcKStkF+xRTJc0gb2A3YR2ZIo16Q+srG6K4BAJ3Hgah+FM77xWkklO5Q06oTqv4ga4Xj +NJIxYEGqwMWvDdh5AkEFrFO3SGhZDQNZHdefZxHgmAtbiUx/2RFnFFho0K08NjxM8PU PPH3O1rdlyOXQFlN/eu1W0vmyssL2u8Pb3WbKxsp3Y+u0nGI+2eI6lJOAZ0ikwf9i981 1Xig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Afvt9npR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h20-20020a63c014000000b005c1e7583b8csi6771703pgg.96.2023.11.19.11.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 11:50:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Afvt9npR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 299B980C1139; Sun, 19 Nov 2023 11:50:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbjKSTuT (ORCPT + 99 others); Sun, 19 Nov 2023 14:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbjKSTtv (ORCPT ); Sun, 19 Nov 2023 14:49:51 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DA91BD9 for ; Sun, 19 Nov 2023 11:49:03 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b1d1099a84so3606091b3a.1 for ; Sun, 19 Nov 2023 11:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423343; x=1701028143; darn=vger.kernel.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=Afvt9npRwp95Im/FJLQ4+yLe4XtjOwRQlS5Bcenqfiu6s4zOVDNDC9TnLd2LDWhRkG Lf2Rk1xnJAxJCu05N3e5x7+kA52CyzE4QJvMnOej7jgkD7/TrKSYRxbeOZEiENa+1ffx vaITqRi5dxBNDB6InBBqOjlYYUHzoHuLXQxS3uUm9Mm/TnDtbYFej+7QIU3OEdCuKRKS UQG2QXnrODblRWZXfWxIhATw7KrBUVCu+krtYU7WYC5sGIqFPI8CE/QBuZK7Otg+aMeK w5ww+J45bGxSYsmDtMx2bO7Ot7hUiqUc+FTLPFYeQUCZv/sjEXwEGjoAB6Y3u1k5xelF gCQQ== 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=hcr1MX/sniu/lkyTjcNc2ScEKn2CY5CQTz1Ha4oLyM/fySwiB1asq7RWacA4ri1yGq yYWiMt2khDWNXvL7kHkj4a4XQhxLEHFfG3UPhnyEPOw+V5WWmrdv/+TfOI1ABPkIHtjA G4TRwR/O1l6oV1wkAjPvhA9s2gIi539cbYqPDmacaUcRNp3yzLHRSidzj0rl7W6IE5Cl Ik1IsK3XR7L1IJSuNqBsfKqhA9TCX70A05aYe12ZvzQ19bW0gLbWB19K6x4RzwH1RURD dMfR6Gk3wi2LFpJClvYimhmK/8VCpvt/CE/JuCl//8SJgZdmMl8C2wkfK/BGA9CLojbl mhtw== X-Gm-Message-State: AOJu0YxMWPGOpR9DEg3WP4XUy3GEhnANX0smxKd1gSjuHkt7Mdc9XQ/G nu7Rxnjvxm3tbMyUpkjapR4= 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 11:50:37 -0800 (PST) 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); -- 2.42.0