Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1522855ybl; Wed, 28 Aug 2019 16:25:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0vRTgPa4/eeKF/XPpFcoQVh56uuJWa2qWTzEG1Egckiq1VarbG7SdmofBxCMWFqsvlz/s X-Received: by 2002:a63:2bd2:: with SMTP id r201mr5541616pgr.193.1567034717777; Wed, 28 Aug 2019 16:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567034717; cv=none; d=google.com; s=arc-20160816; b=qF9kvxbPjzUYOG9wb6KgpOZCgye/zBl1jI6GOUKwi+yvOETPNzNKbV+4FXsy+EMGNg B0oZCkudB2oxCt7HiHRCYh8TYEaTN2tQYFa5jQcUEITAEotVdPXB23BoiuJxKPKuEv5p bZoqbV9kVZ4aCYcf+H1dLdLuMDCYd559joJUuW0VosIuUD/U2RaM0Zo1uDJmQCk5AQ6R j/f7y/bpWgCwKvkHZmuk/ifDYhCmOcLBwqNBk/V/uG+1u8VGLglttOnFH1JNasLM/UlR Z4URaeD6cyDi0g/hkly6efUENoVVbecdosucPvpqKRotyPxYgKEAnMmqkfGkGn5EfKa8 bRiw== 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:dkim-signature; bh=AvN4fIezSJ+C/jhEzDi7EbKP3oKNxT5wmlM2R4Ta9yo=; b=cgio6WIW3DfDoxI4rrhYpe8vg+Mwl+/wq4FQXMpgK4hPxGcwoiotLoijndjT9MSjqR WJEVI5rT5WghsE7AjzkLSmIvIYEy7rCc4s0QN4vfiDBg046EdQkU5fCwJUUVv8oRdklA ZmMZ1HkECFZF3prXcH2/50dkeQsCjirPlAs+xLTqtJKJ7dqrUsq4fHE2K3eEWt/qZfVp KoP2pKacx2hazd2ZUOS5USKEOoy9ykA8dYzG9V7FyAKj/KnhvWRenh9UD7M5fFBbOzYD hUBzhWPevnFzcmJ+3/Cm8Ju38StGrTwKViONou01EZp5RoctTwGKqDlyJilEkSo7X2KY o5RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Am2VYn52; 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 e10si644973pfn.29.2019.08.28.16.25.01; Wed, 28 Aug 2019 16:25:17 -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=fail header.i=@gmail.com header.s=20161025 header.b=Am2VYn52; 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 S1726980AbfH1XWi (ORCPT + 99 others); Wed, 28 Aug 2019 19:22:38 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38198 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbfH1XWi (ORCPT ); Wed, 28 Aug 2019 19:22:38 -0400 Received: by mail-wr1-f68.google.com with SMTP id e16so1475835wro.5 for ; Wed, 28 Aug 2019 16:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=AvN4fIezSJ+C/jhEzDi7EbKP3oKNxT5wmlM2R4Ta9yo=; b=Am2VYn52M2VkcRLpVXKUd3ONA//NUx9LsgmnzWoCqi6sSmj5902FUuI3+SKM/qrstf fHd7a384vhRic7tfTG865HqDs6Ks0EAAgUQdGjUOkkWI9fXbI01R1zaUF0rfYJFog9tf +iCMgrIkBdQ78dufoJxq3g3XEngGFFrYNQXXXJsJij+dBGnr8U4ZNbnsXH+ZNX3CQK1H CQ7lmZKhQVM8nxiTyzPDEzRUfUjFnSilEdfd21k+q+/hGCg5AzKjTGxj+aeOWAjnhNlz PcEDRzJ3i03iraqOYb5gYth2oSkwS8fg8FYl/Y41O4xReY62jepc8LV4V/MI1XjZXO3D f3Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=AvN4fIezSJ+C/jhEzDi7EbKP3oKNxT5wmlM2R4Ta9yo=; b=OJSfUnA6jyNLnsduqQSm39fiBuJqq+gt+pfJ1zqyJnpc9CzGFq8tBo5f/nyMwsIgxA Kc0shaB/+nMYtQeqeXYwI+UxbcVVS1bHKjtE4nyyd7FuqqN9WYkpR82ezkxPxy6nLfw0 +jWzIQpcL99Qpw/fEWgh4nz/XNwZ6Iopi8tsK0LriDHuR6j6f6soVdrajqxRg4Wm2tXK eFOEITGwyUkzV0Q7oG4UJI60KILKwTEMjLbDeetd5hC3yD35TIWIIP3UnqK0WKsNxQr7 +hLmmllsU3sgTfOpFInbAnL3DaKCmP/m4tftG7Hd2J25yBtgbDSEYkJ4fgdcQYKRqQxP joGg== X-Gm-Message-State: APjAAAWo1ZXLKQDDXjCZkzGGq8s4kGZ6r2hK1OsLVSb17i3SRwwDoU2o ToNjfB+lt7kOHqKeK0TzVrU= X-Received: by 2002:a5d:5543:: with SMTP id g3mr7577230wrw.166.1567034556317; Wed, 28 Aug 2019 16:22:36 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id r15sm476059wrj.68.2019.08.28.16.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 16:22:35 -0700 (PDT) Date: Thu, 29 Aug 2019 01:22:33 +0200 From: Ingo Molnar To: Thomas Gleixner Cc: LKML , x86@kernel.org, Song Liu , Joerg Roedel , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Rik van Riel Subject: Re: [patch V3 1/2] x86/mm/pti: Handle unaligned address gracefully in pti_clone_pagetable() Message-ID: <20190828232233.GA99597@gmail.com> References: <20190828142445.454151604@linutronix.de> <20190828143123.971884723@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 * Thomas Gleixner wrote: > From: Song Liu > > pti_clone_pmds() assumes that the supplied address is either: > > - properly PUD/PMD aligned > or > - the address is actually mapped which means that independently > of the mapping level (PUD/PMD/PTE) the next higher mapping > exists. > > If that's not the case the unaligned address can be incremented by PUD or > PMD size incorrectly. All callers supply mapped and/or aligned addresses, > but for the sake of robustness it's better to handle that case properly and > to emit a warning. > > [ tglx: Rewrote changelog and added WARN_ON_ONCE() ] > > Signed-off-by: Song Liu > Signed-off-by: Thomas Gleixner > --- > V2: Negate P[UM]D_MASK for checking whether the offset part is 0 > V3: Fix changelog > --- > arch/x86/mm/pti.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > --- a/arch/x86/mm/pti.c > +++ b/arch/x86/mm/pti.c > @@ -330,13 +330,15 @@ pti_clone_pgtable(unsigned long start, u > > pud = pud_offset(p4d, addr); > if (pud_none(*pud)) { > - addr += PUD_SIZE; > + WARN_ON_ONCE(addr & ~PUD_MASK); > + addr = round_up(addr + 1, PUD_SIZE); > continue; > } > > pmd = pmd_offset(pud, addr); > if (pmd_none(*pmd)) { > - addr += PMD_SIZE; > + WARN_ON_ONCE(addr & ~PMD_MASK); > + addr = round_up(addr + 1, PMD_SIZE); > continue; > } Reviewed-by: Ingo Molnar Thanks, Ingo