Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1836724imc; Tue, 12 Mar 2019 01:26:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzu+uXICF+yrobwbA7EXKdo06h91keE8C6o0t/SlpOB32wvxerEo8dAtZ68OeJlF/obtaie X-Received: by 2002:a65:514a:: with SMTP id g10mr7083265pgq.400.1552379210418; Tue, 12 Mar 2019 01:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552379210; cv=none; d=google.com; s=arc-20160816; b=0MIFznI8VrmIcgdpX813uQ7FR49EKzuQA6Q+R7/aW5xiLcJ5GR9nIiI3OiicSnkpiQ RM/W+684gcOi78WQMUA6MgPk/hg+xfGqRBT2H/NxIxxcObzWH7k5AS37bMppw0JNMjWI 5JvmVMo7ibA9BR7VaQRyjTsyWQnfRG/5fL3Emi4Oy/Rv7cMWgd79gZoVyl8yYEJrssu7 rtCBkTsT3O6bCtZR1KjBieLcVjW7+bEYNqoU//zkcnomQ3erDCAr5vNNAf47NyJqzn+e gClJnzgi4fyMsR0p8fA6mJH5sLks/isCw4c9D8bHz3VBMBK+xuond9Oeny3hfpDVdt0H mB+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+kHmZqJQZPgvsZdhKJOhctGi82pkXKzXA+M60O8j93Q=; b=U/h1YHeCStDCWt7jekgsnOXTC+gpTwUwRn6Z12UlkRkJKxEsCdfXBH79zNAJ0w33RD c9sVfnlikJlogIhtSDh8unr5JeY/5AdUjczzP/TiqsQBxOv1MsdndjPWB5OGC7/g/lnv 6LTsBE7KVZBfn3vYgYf7Hn3KJUQ1cdUsDDIXAAQRJCVFJoeJUse0T6uqibN1bKYcN0Qz reT0eJKBySYJWirLJCuzGIoZsHsEouE7Yp/5oODEFRamy6s4atjZMyyWpgOYrlYOhAJ1 5sAmXY6oZH+uxQN7pX2OWIPKDbN5dk8/hBb2nt64u2BQNirtb73zKBfAKz29Ev53gqWM E3wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si6454826pgp.376.2019.03.12.01.26.33; Tue, 12 Mar 2019 01:26:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbfCLI0P (ORCPT + 99 others); Tue, 12 Mar 2019 04:26:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:46018 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725832AbfCLI0O (ORCPT ); Tue, 12 Mar 2019 04:26:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1BA30B157; Tue, 12 Mar 2019 08:26:13 +0000 (UTC) Date: Tue, 12 Mar 2019 09:26:12 +0100 From: Michal Hocko To: Pi-Hsun Shih Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Stephen Rothwell , Minchan Kim , Huang Ying , Wei Yang , Yang Shi , Aaron Lu , Tejun Heo , Omar Sandoval , open list Subject: Re: [PATCH v2] mm/swap: Use offsetof instead of custom __swapoffset macro. Message-ID: <20190312082612.GH5721@dhcp22.suse.cz> References: <20190307094653.119425-1-pihsun@chromium.org> <20190312081902.223764-1-pihsun@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190312081902.223764-1-pihsun@chromium.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 12-03-19 16:18:59, Pi-Hsun Shih wrote: > Use offsetof to calculate offset of a field to take advantage of > compiler built-in version when possible, and avoid UBSAN warning when > compiling with Clang: > > UBSAN: Undefined behaviour in mm/swapfile.c:3010:38 > member access within null pointer of type 'union swap_header' > CPU: 6 PID: 1833 Comm: swapon Tainted: G S 4.19.23 #43 > Call trace: > dump_backtrace+0x0/0x194 > show_stack+0x20/0x2c > __dump_stack+0x20/0x28 > dump_stack+0x70/0x94 > ubsan_epilogue+0x14/0x44 > ubsan_type_mismatch_common+0xf4/0xfc > __ubsan_handle_type_mismatch_v1+0x34/0x54 > __se_sys_swapon+0x654/0x1084 > __arm64_sys_swapon+0x1c/0x24 > el0_svc_common+0xa8/0x150 > el0_svc_compat_handler+0x2c/0x38 > el0_svc_compat+0x8/0x18 > > Signed-off-by: Pi-Hsun Shih Yes this makes more sense. I still think the warning is bogus but whatever. A cleanup is worth it. Acked-by: Michal Hocko > --- > include/linux/swap.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index fc50e21b3b88..4bfb5c4ac108 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -157,9 +157,9 @@ struct swap_extent { > /* > * Max bad pages in the new format.. > */ > -#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x) > #define MAX_SWAP_BADPAGES \ > - ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int)) > + ((offsetof(union swap_header, magic.magic) - \ > + offsetof(union swap_header, info.badpages)) / sizeof(int)) > > enum { > SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ > -- > 2.21.0.360.g471c308f928-goog > -- Michal Hocko SUSE Labs