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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90B17C433F5 for ; Sun, 14 Nov 2021 03:10:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB92461029 for ; Sun, 14 Nov 2021 03:10:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EB92461029 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CE94A6B0075; Sat, 13 Nov 2021 22:10:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C96EA6B0078; Sat, 13 Nov 2021 22:10:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B857A6B007B; Sat, 13 Nov 2021 22:10:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id A85AD6B0075 for ; Sat, 13 Nov 2021 22:10:42 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 57E2982D88 for ; Sun, 14 Nov 2021 03:10:42 +0000 (UTC) X-FDA: 78806058324.06.AA58037 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by imf18.hostedemail.com (Postfix) with ESMTP id CF0BF400208B for ; Sun, 14 Nov 2021 03:10:41 +0000 (UTC) Received: by mail-ed1-f53.google.com with SMTP id w1so55146534edd.10 for ; Sat, 13 Nov 2021 19:10:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R2F7Q0/8HUDfOf3xlyKhCBtDnVOrxRnjR5LDyBDPovQ=; b=gf43TvW0tZqiIMYlXaM61JHO8QMFQaZG885oMn77nEnpLN6DsAGZSA2QwABlMRp2gI +sXpPQi13kcfCTZN9zHJU0v4V0QHnsH2Qb7InvdxUsQ1M6DaJavp3l+hJD6SI+hPCDi7 TapgLMHOoV5S3JOhnCo+aScRERVgSwe4MO4Ozn7Kvd4z6KlGSiNTG+M+GvqQKzet5UHX /eusgz/JBBNsm/al3mIokGzcrkbYNuKyF1aRjMgR6RzRwySMFdP96H4Z0jnFepNQox5y 23/N3g2LOAvGgkbE8vH/AHulNCoeU9/kCUTCn6Xw5/mGGyBIhPl4z4GkU/KAhnLp3tar +Hlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R2F7Q0/8HUDfOf3xlyKhCBtDnVOrxRnjR5LDyBDPovQ=; b=F8MCf9Duz3VOohZc1RkD7RDhbP+Rbxtq8glIlxxw28oXZxktzEu7B3qlbtIRrx63JU EoS0fE3Tru0GSFj6h+Nv9cF3AT6eIycNa2HEaseBZWJVoVEvaxv9qeBzHw7Ddko+7YXX e9SFt7//MahWYcDZmHl3950zTl1/2nVyPLe0o7CfA8t+yf1aL7iv38+luJWWAXr5sgWd 6U46QbYs/No4a2LVODUp29vBnIC9snlHE1xShOk1NZ1QEEOuDz07XoJNnN/U04l/P0bl LrJu9I2cNbbzf6OzUv1au+1la6FGDVG8JQDMRzhAeSYL3AiVs9PvlQplizqyMO+rdor3 plvA== X-Gm-Message-State: AOAM532XGrczOWX43vshd81kpMHO9k+pMua4JzsYf4VYWLzQPWa5R0eB VKeDS7jZEdhGm2a+rRsh94yMubw/TZbuBDzUD+8= X-Google-Smtp-Source: ABdhPJyA8C5dSjxUYjyiZqRfiAMNK4XF/oYMDNef/P58tgOFk+Rv3qUPYpepYz7d6n/V3uiS9SM6ueaYpELXo2HS5yo= X-Received: by 2002:a17:907:1dd5:: with SMTP id og21mr36527409ejc.233.1636859440463; Sat, 13 Nov 2021 19:10:40 -0800 (PST) MIME-Version: 1.0 References: <20211111084617.6746-1-ajaygargnsit@gmail.com> <628a49dc-f6f7-5aa4-8a4d-4f2ed19b7f3f@kernel.dk> In-Reply-To: From: Yang Shi Date: Sat, 13 Nov 2021 19:10:28 -0800 Message-ID: Subject: Re: [PATCH] mm: shmem: do not call PageHWPoison on a ERR-page To: Linus Torvalds Cc: Jens Axboe , Arnd Bergmann , Ajay Garg , Hugh Dickins , Andrew Morton , Linux-MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CF0BF400208B X-Stat-Signature: a39yhuaf5jgteffpik6jt5ezdx4ztsa3 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gf43TvW0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1636859441-628529 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 Sat, Nov 13, 2021 at 2:58 PM Linus Torvalds wrote: > > On Sat, Nov 13, 2021 at 2:30 PM Yang Shi wrote: > > > > The above snippet is actually ok since if *pagep returned via > > shmem_getpage()'s parameter is not NULL, then ret is 0. > > That's a random implementation detail, and is not ok to rely on. > > It may or may not be true, and is not part of the rules of error handling. > > If a function returns an error, you shouldn't be looking at the other > stuff it returned. > > Here's a very recent example of the same kind of problem: > > https://lore.kernel.org/lkml/163663333331.414.639840290224641315.tip-bot2@tip-bot2/ > > where people didn't actually look properly at the return value of the > function, and instead looked at the page pointers that the function > filled in. > > See? EXACT same logic. And completely buggy. Yes, I agree it is too fragile to rely on. > > > When shmem_getpage() returns error code, *pagep is NULL IIUC. > > No. > > When a function returns an error code, you check for the error code, > and don't rely on weather the function then filled in other data (or > left it alone, or whatever). > > So the code should > > (a) check and handle error returns properly > > (b) be legible > > That (b) basically means that if it's not entirely trivial (and none > of this was entirely trivial), then when you get an error, you just > deal with it right away. You return early, and undo anything you need > to undo. > > You don't do "oh, let's keep that error, and then do something else > that maybe also generates an error". > > That "don't handle the error directly" was why > shmem_read_mapping_page_gfp() was buggy and would cause an oops. > > And while the shmem_write_begin() code migth not cause an oops, it had > the same fundamental bad pattern. > > Error handling is where 99% of all problems occur. But that also means > that you should do the obvious thing wrt error handling, and not have > some crazy "if function X returned an error, it will have left the > return array untouched" which may or may not be true. > > When a function returns an error code, you do error handling based on > that code. Not on some random other state. Thanks a lot for the thorough explanation. Preparing a new patch. > > Linus