Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5077202rwe; Tue, 18 Apr 2023 01:31:39 -0700 (PDT) X-Google-Smtp-Source: AKy350ZZuzpHofaCmC+e5/vIL84GAscgmcFHVVyVuxgv9/PCo+4N4AxROLUjJuXI7w2X42q7wfaG X-Received: by 2002:a05:6a20:1603:b0:f0:a308:1823 with SMTP id l3-20020a056a20160300b000f0a3081823mr1573601pzj.23.1681806699444; Tue, 18 Apr 2023 01:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681806699; cv=none; d=google.com; s=arc-20160816; b=SxlZEtHAzhw9cTtNX0QUFRcL58DxRFaaFGnUeQD10JhBukk4bx8i7u7lgZ9bBFq1+B i1E8G64br2q5zpmY3/XCtiEFcZerK522m3g6j/8OnwvP9TumAEymaEDyOmWLKyY+FiLR awXm2X1gyB8ogPVhSsDCdbnLW1sXZ2sKDqy2QJz/qZAQwHQzSsBAA1V9eXDoeTPHPyvi b3iImOSqaVrQ6tfpkSMndnUF2/VkTny9GUMYKLstsH+Pm7Yjd0BQrzSt2PN7aQ6Ie2aQ RngpoMa4j3VO4xSSHL2YoBopdo8e7QIHncsY8JACT43MBhzPztmpSNujAQoNBkAB3IGd dY4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5fuQkHKWI/lgpNcFt6ZdMNne2pX3w0YtDWS0YTqJBCI=; b=Rskd77Ktjunc/TewYsNtIHREfrlQ7uYzPxuYbCV9iT1KWXXn89c18g4ek7AlehXr/j 2YhJ3SQI469W9KgyhdJbm1crLeY88/Kk+UtiR6a915mCfhO//GzzHp+Uyt2Zo+Mf3y+O 1sCstLB0GJK4wn68B3WpWqDJBJ1tUGnpdXhFqln5PSvoPIojfCVmmzMdiHyTuprBWncx S8mqa/AdawUGKoLw9ZGRQwxPxBBs9TCHkmV/XGlXGqgbXb6q9X7epnAA7GA9goXpgjWw XVlvXr9Jixf1+tFdEzYA4TmW5DBs6BterG1TGQnY63z3rKX6tvwpzXE0G2YSzFjawSDb jfug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bKYT1lQF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a70-20020a639049000000b0051b8a81c5d0si8579078pge.606.2023.04.18.01.31.26; Tue, 18 Apr 2023 01:31:39 -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=@chromium.org header.s=google header.b=bKYT1lQF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbjDRINT (ORCPT + 99 others); Tue, 18 Apr 2023 04:13:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbjDRINR (ORCPT ); Tue, 18 Apr 2023 04:13:17 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B4456A47 for ; Tue, 18 Apr 2023 01:13:15 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4ec88c67b2eso1937150e87.1 for ; Tue, 18 Apr 2023 01:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681805593; x=1684397593; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5fuQkHKWI/lgpNcFt6ZdMNne2pX3w0YtDWS0YTqJBCI=; b=bKYT1lQF+ceywACbQRsaGEYOk9yAX3tfN/xOqXX9bhvZZf6j6UTjmGixXbFHfp4+YE zdw4u3y0ZPeZCUBFWtiwbwtX7p8OTfU3e1abCNbqqoa+GS8vK9GT6INbvWfqdfHipeNn YSi24AcgUJfX86Cu9UFpPw+PyjT/J/ZYJ1Fh8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681805593; x=1684397593; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5fuQkHKWI/lgpNcFt6ZdMNne2pX3w0YtDWS0YTqJBCI=; b=Yi4vP933R/ODOC4/7OhaOZqaKrCFV7PVoExG8lvWmHS53ajgb4rnXfpmH8ICTozUoI AKUc5eatEsDMgYtN4x3OlACV6PegAY2WkSW4RyNMa862txV9yE3J5x08yKwCpIuBENGV UxKhQLUGmaQ7PDU09dG22B1kJOrvOKQVaVJV10PFaU3XBT9rlPyLantP4/W6u5Q5QN6Q aC22dKG1x8sBYp9ke7WtxgRmr3m1n0pjgMtqF4iSraXvZmBeUExm3+fkbbE+Q1ktulNi inUmLPZeyL4ZnhwasAAtfDsUu/4sEnNWk3WeDTV7L6bbQrVQ036rzoxbCTGKHr3PZSFU o2Eg== X-Gm-Message-State: AAQBX9dHOp+LMu3r+hpVMO7oaq95Z0TE8EYAiy/XVvxYiEPK0U4wYoKv i0NELUhqLFXP5Rua6m/LV/afIygfKI9t7c/MX/KHCA== X-Received: by 2002:a19:f60d:0:b0:4ec:8ca6:65ad with SMTP id x13-20020a19f60d000000b004ec8ca665admr2961873lfe.11.1681805593322; Tue, 18 Apr 2023 01:13:13 -0700 (PDT) MIME-Version: 1.0 References: <20230418061933.3282785-1-stevensd@google.com> In-Reply-To: <20230418061933.3282785-1-stevensd@google.com> From: David Stevens Date: Tue, 18 Apr 2023 17:13:02 +0900 Message-ID: Subject: Re: [PATCH] mm/shmem: Fix race in shmem_undo_range w/THP To: linux-mm@kvack.org Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , Suleiman Souhlal , linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 Tue, Apr 18, 2023 at 3:22=E2=80=AFPM David Stevens wrote: > > From: David Stevens > > Split folios during the second loop of shmem_undo_range. It's not > sufficient to only split folios when dealing with partial pages, since > it's possible for a THP to be faulted in after that point. Calling > truncate_inode_folio in that situation can result in throwing away data > outside of the range being targeted. > > Fixes: b9a8a4195c7d ("truncate,shmem: Handle truncates that split large f= olios") > Cc: stable@vger.kernel.org > Signed-off-by: David Stevens > --- > mm/shmem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 9218c955f482..317cbeb0fb6b 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1033,7 +1033,7 @@ static void shmem_undo_range(struct inode *inode, l= off_t lstart, loff_t lend, > } > VM_BUG_ON_FOLIO(folio_test_writeback(foli= o), > folio); > - truncate_inode_folio(mapping, folio); > + truncate_inode_partial_folio(folio, lstar= t, lend); It was pointed out to me that truncate_inode_partial_folio only sometimes frees the target pages. So this patch does fix the data loss, but it ends up making partial hole punches on a THP not actually free memory. I'll send out a v2 that properly calls truncate_inode_folio after splitting a THP. -David > } > folio_unlock(folio); > } > -- > 2.40.0.634.g4ca3ef3211-goog >