Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2058968yba; Tue, 2 Apr 2019 23:52:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQIEcpNyWrQirBvcAty8eNUhwrPeE6/dhig3DZUAwqfwut1xT0mtbqSDBRaLOGAbCDtMlI X-Received: by 2002:a17:902:2888:: with SMTP id f8mr76204870plb.244.1554274359042; Tue, 02 Apr 2019 23:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554274359; cv=none; d=google.com; s=arc-20160816; b=DJxKlLsSr9m4Nye9M08LYMmj1+aXcFXDuTLJhasb9DEGKU1kmlNNZMYoZHMRaRL2rr nPHbRjpfOKimwhpW9qLO8IcEaWvF8mtKoXUT1j4N0SHxasqKiiSRDrYeA5M/HFI8GBKs sPp+lIlsdw2Nnn4SUfibcMRLRN1g6Awn/2Zy8HgmhE5/R7R0ikcp55wy8Nzv3hg8ejQL DHMSGnWloosaBudWtj2xEipApisRD3zVgDouKawIZYnTlbG6ao1CVQQt1zmxwboA4WMU YGxYywe8kkNFR1E+fqHqet8r7GGdUZHCCcfiLw7ENWaOsUiMxz/b2emRMQChZNhfy/ib okMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=cNvWAUPihXUG8tk5r2OE77Ss4iGVr1lrjgN2yALMW6Y=; b=ZRbNy9wdYcFooXC/6DtaZL5SFoBcOUecXzt3SnVimAMgzqZlpgap9XNYkYGAPaOP8q kF9WPMrUo6z6dmv7qVRKAfBBzC1d5U6r4hmguINTVo7VpvfJoHz9VX7rsIV2dhAaQ4hp X3YQuFoS5ZvZre7HnkSr0NTc4LQ2nYPywrS89+1j3B5odTdFpIEdHXOvRZXgyG0DRqRu bzeu2CQHKc28VJWLlpME+BZrFps0Z/k4osGqn1cjslBTOMB3JvDatY2TPm7tbymPS7Au NQea/WhdkbaSxNe/SNJO+m0rPGMn2K6brD0y1NTki2rq8JJ+ZS9HeJAPTSgLEAfvKYYY K61w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=apsB5Kqv; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si12765409pfi.21.2019.04.02.23.52.23; Tue, 02 Apr 2019 23:52:39 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=apsB5Kqv; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728625AbfDCGuL (ORCPT + 99 others); Wed, 3 Apr 2019 02:50:11 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41460 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726048AbfDCGuL (ORCPT ); Wed, 3 Apr 2019 02:50:11 -0400 Received: by mail-lj1-f195.google.com with SMTP id k8so5411031lja.8 for ; Tue, 02 Apr 2019 23:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cNvWAUPihXUG8tk5r2OE77Ss4iGVr1lrjgN2yALMW6Y=; b=apsB5Kqv2C79wmC3nMkAEKQ3og2Vde9hp874tiRDUZXhpms3NOMimwlVSFw3P3U8Ex UaypKS/NvUz5RplwRbElxdctcuNXxlkUt56Jt0LW4Id5SASCbICwGhwCpiGmg2A98Tsx L6hHoD1OStyjHTtv2Bj5/G71ypbj+EtZHJAFE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cNvWAUPihXUG8tk5r2OE77Ss4iGVr1lrjgN2yALMW6Y=; b=NOZ/rNf/aRxtyRBSCTxplzEn3Z82iPFcMiIrdjfqcSJFY1PxJoF9IFJ0uCdKR/Ls60 C+7G3qHfdJblia4QDNb9XV7gbzICRjF5GvSpa6L7n8QJljk1o2Hhmp5feSVZ/dfA4QPd 59b6U0zPqP2+RaPuS98uz5u7NXd/ECB+PQ5S/Z6lcK2tM/pmN5EByY2qpUjztcxDPiMC t66//MeYnFVcGWc3MCfSqrveoYNgztuxbPet2KWfOiIk1zP70FKNBdQPRkUUD47C9QmM vOOlXxt8xc6qWkDmrAsqNIUn8iTuJSwlakbxzgKegbDXhcn2QeJtd0cYEA/cOM2Y+sp2 /KFA== X-Gm-Message-State: APjAAAVZeGQhQb3aegYQ+WMN/sV6cQzavZzaSvguZbOZYjIu9/18zMsk dUQfRV2R4whWO6JGfme5N9GEyyNCup0v1enY X-Received: by 2002:a05:651c:114:: with SMTP id a20mr40736396ljb.53.1554274209142; Tue, 02 Apr 2019 23:50:09 -0700 (PDT) Received: from [172.16.11.26] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id k21sm3064532ljk.21.2019.04.02.23.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 23:50:07 -0700 (PDT) Subject: Re: [PATCH v2] ubsan: Avoid unnecessary 128-bit shifts To: George Spelvin , Andrey Ryabinin Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Heiko Carstens References: <201904030545.x335jQJO015258@sdf.org> From: Rasmus Villemoes Message-ID: <1cea9e60-204a-44d5-96dc-606c0738c621@rasmusvillemoes.dk> Date: Wed, 3 Apr 2019 08:50:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <201904030545.x335jQJO015258@sdf.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/04/2019 07.45, George Spelvin wrote: > > diff --git a/lib/ubsan.c b/lib/ubsan.c > index e4162f59a81c..a7eb55fbeede 100644 > --- a/lib/ubsan.c > +++ b/lib/ubsan.c > @@ -89,8 +89,8 @@ static bool is_inline_int(struct type_descriptor *type) > static s_max get_signed_val(struct type_descriptor *type, unsigned long val) > { > if (is_inline_int(type)) { > - unsigned extra_bits = sizeof(s_max)*8 - type_bit_width(type); > - return ((s_max)val) << extra_bits >> extra_bits; > + unsigned extra_bits = sizeof(val)*8 - type_bit_width(type); > + return (signed long)val << extra_bits >> extra_bits; > } Maybe add some #ifdef BITS_PER_LONG == 64 #define sign_extend_long sign_extend[32/64] stuff to linux/bitops.h and write this as sign_extend_long(val, type_bit_width(type)-1)? Or do it locally in lib/ubsan.c so that "git grep" will tell that it's available once the next potential user comes along. Btw., ubsan.c is probably compiled without instrumentation, but it would be a nice touch to avoid UB in the implementation anyway (i.e., the left shift should be done in the unsigned type, then cast to signed and right-shifted). Rasmus