Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7249856pxb; Thu, 18 Feb 2021 05:36:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvMaf5kyAFJtLj7CIpU3tbgYbRrWihT5aux4cX2ADCeWc6ENxQRrzrarr1jqK8Wk7R/aVB X-Received: by 2002:aa7:d90b:: with SMTP id a11mr4228038edr.250.1613655395336; Thu, 18 Feb 2021 05:36:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613655395; cv=none; d=google.com; s=arc-20160816; b=Li+JBHXQpVg8QVUabJPOF4QwllRhve34JngpP4/pf1gLc2NYRJS6mei7mqmthZp3i3 5WJw72e6FnOEjfXE84qFKGL1eSeqKu7cbYtA8Ij+k9KJb5oh8UcoRc7MFVMpDMsv4N+k zQBrsJXJH0xqWV1M50ty0tlOelXB04uGaz+8T/+4Xn6nYEHxZGNjnclqGTz5zCqmLkAo 5DVeUV8NEGLCCAdXp5HnX6I9m7HRWV+dsIuB+Nlgddu3en32Z6WDosAPiFQj7/kSUiGF IDFNPFYKzUhWYWKfTjUJ0XacPjQqNjfX8VAE5F1Df4tiVcA4+mUmXY7UOzubRIDPdkVA PNww== 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=wdITicK6JXxZpGr3P+/WWK+hk6TbR/XmnHaEfBjS0V4=; b=GGNB68iEd7a2Jhncy/2OA8E3NX57CAJwuoXrVPp0vZBPziAVOqh2h6h2gHITiKqbPQ 20xsDgvTqWaIJpL1XzW78vfiGRTSNs3suckbXQrckUnREx5za628madZNQi7P+lCZELY CQAdaaGk7rmNH9gvRfmLJfzBBE1awchTuBWhli1YFPHhSLPZpbthzEHRUykf08FL+13w m2+LZbT/k6g03cJmXxPPjlEP8bjyxq6c56YlMzXYapkcCspyOhSnuav58uoI6rgAfGNC vugF5Q1Pbpmryr0WVH0IZukSJjWAbyqXW/l+PM04gpocbx0fvssRazY0r1HB3Kk5/HUR P6JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=T6atSr7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si3493810ejz.76.2021.02.18.05.36.09; Thu, 18 Feb 2021 05:36:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=T6atSr7V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbhBRNd5 (ORCPT + 99 others); Thu, 18 Feb 2021 08:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbhBRLtB (ORCPT ); Thu, 18 Feb 2021 06:49:01 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15BC3C061788 for ; Thu, 18 Feb 2021 03:36:27 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id v206so1708465qkb.3 for ; Thu, 18 Feb 2021 03:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=wdITicK6JXxZpGr3P+/WWK+hk6TbR/XmnHaEfBjS0V4=; b=T6atSr7VLAVP/Ph1kZBvz50str3UNX2H5Sa+OJVQxSS99ZOsthXeN/nSR7s3glUxr3 cvfJJz53mAqjhvewwiSS3ZDwcXb70IM0KjvfIbHh4a8jxEKQ3TSwDu3PFX8AEhh3jFIr BDmJ4er5dV9ihrV+Xe4wYedV0m7u6zzkIWTrvIMfqaSgdid7ZimuZHl1NndINWOrz2My KGV5yiaxJrRFYAX84vqMW0l7Gg6zJSGvJsfWtE1gls4eXr6Ns/pBw/1CxwpKUutnKLDl JeY1tjoV+UAmBXk89LHnWKCqUEvAIO02Zd0SX0mt56EX9P3i/Y885hgcAAbldfxo0mCS aNpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=wdITicK6JXxZpGr3P+/WWK+hk6TbR/XmnHaEfBjS0V4=; b=uI9n6CmtGaq3ErR0fJtxTFjcbqzFcgbhic418V2cGkhCjQlkYDrgV7b5E3CIiQsHV2 UXInDusiu6OpWJf9MaJUQqhK6bKvAjyGs7pN8wyaBaUx0o5Cl+JgfB0rx4g894mGv8L2 5PMh0486RowThAfFBKMBxfpbWyiMBajnQVotn9Q8z0iyoTHqRqKmUl+hxXF0S7d1bjX3 hgXDsS+j8RPSjQ89yZH3qu7ONll68wPkdNvBOa5PLMeVWW0ZKnCQ8QsgO7aI39NcPiER OX8GdqGvMDXWhlNopDjzyVXUvWGdJ6umw3RaHBDCi/1Ubcb6BdpDEvDxGTdFrgED2Jqw bKeA== X-Gm-Message-State: AOAM531TX1PJHi65bavwNfLijUZZUDrDeVzvNmT1+IGhWtLWuwdw87LG idzhwrJebrJtfDi44w5PGdtTGpNI/Mr9tFDNeQD/yw== X-Received: by 2002:a37:46cf:: with SMTP id t198mr3736652qka.265.1613648185754; Thu, 18 Feb 2021 03:36:25 -0800 (PST) MIME-Version: 1.0 References: <20210118145310.crnqnh6kax5jqicj@distanz.ch> <6e9ee3a1-0e16-b1fc-a690-f1ca8e9823a5@ghiti.fr> <24857bfc-c557-f141-8ae7-2e3da24f67f5@ghiti.fr> <957f09fb-84f4-2e0a-13ab-f7e4831ee7d0@ghiti.fr> In-Reply-To: From: Dmitry Vyukov Date: Thu, 18 Feb 2021 12:36:14 +0100 Message-ID: Subject: Re: riscv+KASAN does not boot To: Alex Ghiti Cc: Albert Ou , Bjorn Topel , Palmer Dabbelt , LKML , nylon7@andestech.com, syzkaller , Andreas Schwab , Paul Walmsley , Tobias Klauser , linux-riscv Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 18, 2021 at 8:54 AM Alex Ghiti wrote: > > Hi Dmitry, > > > On Wed, Feb 17, 2021 at 5:36 PM Alex Ghiti wrote: > >> > >> Le 2/16/21 =C3=A0 11:42 PM, Dmitry Vyukov a =C3=A9crit : > >>> On Tue, Feb 16, 2021 at 9:42 PM Alex Ghiti wrote: > >>>> > >>>> Hi Dmitry, > >>>> > >>>> Le 2/16/21 =C3=A0 6:25 AM, Dmitry Vyukov a =C3=A9crit : > >>>>> On Tue, Feb 16, 2021 at 12:17 PM Dmitry Vyukov = wrote: > >>>>>> > >>>>>> On Fri, Jan 29, 2021 at 9:11 AM Dmitry Vyukov = wrote: > >>>>>>>> I was fixing KASAN support for my sv48 patchset so I took a look= at your > >>>>>>>> issue: I built a kernel on top of the branch riscv/fixes using > >>>>>>>> https://github.com/google/syzkaller/blob/269d24e857a757d09a89808= 6a2fa6fa5d827c3e1/dashboard/config/linux/upstream-riscv64-kasan.config > >>>>>>>> and Buildroot 2020.11. I have the warnings regarding the use of > >>>>>>>> __virt_to_phys on wrong addresses (but that's normal since this = function > >>>>>>>> is used in virt_addr_valid) but not the segfaults you describe. > >>>>>>> > >>>>>>> Hi Alex, > >>>>>>> > >>>>>>> Let me try to rebuild buildroot image. Maybe there was something = wrong > >>>>>>> with my build, though, I did 'make clean' before doing. But at th= e > >>>>>>> same time it worked back in June... > >>>>>>> > >>>>>>> Re WARNINGs, they indicate kernel bugs. I am working on setting u= p a > >>>>>>> syzbot instance on riscv. If there a WARNING during boot then the > >>>>>>> kernel will be marked as broken. No further testing will happen. > >>>>>>> Is it a mis-use of WARN_ON? If so, could anybody please remove it= or > >>>>>>> replace it with pr_err. > >>>>>> > >>>>>> > >>>>>> Hi, > >>>>>> > >>>>>> I've localized one issue with riscv/KASAN: > >>>>>> KASAN breaks VDSO and that's I think the root cause of weird fault= s I > >>>>>> saw earlier. The following patch fixes it. > >>>>>> Could somebody please upstream this fix? I don't know how to add/r= un > >>>>>> tests for this. > >>>>>> Thanks > >>>>>> > >>>>>> diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/v= dso/Makefile > >>>>>> index 0cfd6da784f84..cf3a383c1799d 100644 > >>>>>> --- a/arch/riscv/kernel/vdso/Makefile > >>>>>> +++ b/arch/riscv/kernel/vdso/Makefile > >>>>>> @@ -35,6 +35,7 @@ CFLAGS_REMOVE_vgettimeofday.o =3D $(CC_FLAGS_FTR= ACE) -Os > >>>>>> # Disable gcov profiling for VDSO code > >>>>>> GCOV_PROFILE :=3D n > >>>>>> KCOV_INSTRUMENT :=3D n > >>>>>> +KASAN_SANITIZE :=3D n > >>>>>> > >>>>>> # Force dependency > >>>>>> $(obj)/vdso.o: $(obj)/vdso.so > >>>> > >>>> What's weird is that I don't have any issue without this patch with = the > >>>> following config whereas it indeed seems required for KASAN. But whe= n > >>>> looking at the segfaults you got earlier, the segfault address is 0x= bb0 > >>>> and the cause is an instruction page fault: this address is the PLT = base > >>>> address in vdso.so and an instruction page fault would mean that som= eone > >>>> tried to jump at this address, which is weird. At first sight, that = does > >>>> not seem related to your patch above, but clearly I may be wrong. > >>>> > >>>> Tobias, did you observe the same segfaults as Dmitry ? > >>> > >>> > >>> I noticed that not all buildroot images use VDSO, it seems to be > >>> dependent on libc settings (at least I think I changed it in the > >>> past). > >> > >> Ok, I used uClibc but then when using glibc, I have the same segfaults= , > >> only when KASAN is enabled. And your patch fixes the problem. I will t= ry > >> to take a look later to better understand the problem. > >> > >>> I also booted an image completely successfully including dhcpd/sshd > >>> start, but then my executable crashed in clock_gettime. The executabl= e > >>> was build on linux/amd64 host with "riscv64-linux-gnu-gcc -static" > >>> (10.2.1). > >>> > >>> > >>>>> Second issue I am seeing seems to be related to text segment size. > >>>>> I check out v5.11 and use this config: > >>>>> https://gist.github.com/dvyukov/6af25474d455437577a84213b0cc9178 > >>>> > >>>> This config gave my laptop a hard time ! Finally I was able to boot > >>>> correctly to userspace, but I realized I used my sv48 branch...Eithe= r I > >>>> fixed your issue along the way or I can't reproduce it, I'll give it= a > >>>> try tomorrow. > >>> > >>> Where is your branch? I could also test in my setup on your branch. > >>> > >> > >> You can find my branch int/alex/riscv_kernel_end_of_address_space_v2 > >> here: https://github.com/AlexGhiti/riscv-linux.git > > > > No, it does not work for me. > > > > Source is on b61ab6c98de021398cd7734ea5fc3655e51e70f2 (HEAD, > > int/alex/riscv_kernel_end_of_address_space_v2) > > Config is https://gist.githubusercontent.com/dvyukov/6af25474d455437577= a84213b0cc9178/raw/55b116522c14a8a98a7626d76df740d54f648ce5/gistfile1.txt > > > > riscv64-linux-gnu-gcc -v > > gcc version 10.2.1 20210110 (Debian 10.2.1-6+build1) > > > > qemu-system-riscv64 --version > > QEMU emulator version 5.2.0 (Debian 1:5.2+dfsg-3) > > > > qemu-system-riscv64 \ > > -machine virt -smp 2 -m 2G \ > > -device virtio-blk-device,drive=3Dhd0 \ > > -drive file=3Dimage-riscv64,if=3Dnone,format=3Draw,id=3Dhd0 \ > > -kernel arch/riscv/boot/Image \ > > -nographic \ > > -device virtio-rng-device,rng=3Drng0 -object > > rng-random,filename=3D/dev/urandom,id=3Drng0 \ > > -netdev user,id=3Dnet0,host=3D10.0.2.10,hostfwd=3Dtcp::10022-:22 -devic= e > > virtio-net-device,netdev=3Dnet0 \ > > -append "root=3D/dev/vda earlyprintk=3Dserial console=3DttyS0 oops=3Dpa= nic > > panic_on_warn=3D1 panic=3D86400 earlycon" > > It still works for me but I had to disable CONFIG_DEBUG_INFO_BTF (I > don't think that changes anything at runtime). But your above command > line does not work for me as it appears you do not load any firmware, if > I add -bios images/fw_jump.elf, it works. But then I don't know where > your opensbi output below comes from... > > And regarding your issue with calling clock_gettime 'directly' compared > to using the syscall, I have the same consistent output from both calls. > > I have an older gcc (9.3.0) and the same qemu. I think what is missing > here is your buildroot config, so that we have the exact same > environment: could you post your buildroot config as well ? I don't think the image is relevant because I don't even get to kernel code. If the kernel will complain about no init later, that's fine. Re bios, this version of qemu already has OpenSBI bios builtin, you can pass -bios default, but that's, well, the default :) Here are more reproducible repro instructions that capture gcc and qemu. I think gcc version may be potentially relevant as I suspect code size. curl https://gist.githubusercontent.com/dvyukov/6af25474d455437577a84213b0c= c9178/raw/55b116522c14a8a98a7626d76df740d54f648ce5/gistfile1.txt > $KERNEL_SRC/.config docker pull gcr.io/syzkaller/syzbot docker run -it -v $KERNEL_SRC:/kernel gcr.io/syzkaller/syzbot cd /kernel make -j72 ARCH=3Driscv CROSS_COMPILE=3Driscv64-linux-gnu- olddefconfig make -j72 ARCH=3Driscv CROSS_COMPILE=3Driscv64-linux-gnu- qemu-system-riscv64 -machine virt -smp 2 -m 4G -kernel arch/riscv/boot/Image -nographic -append "earlycon earlyprintk=3Dserial console=3DttyS0" [this does not, only OpenSBI output] scripts/config -d KASAN_INLINE -e KASAN_OUTLINE -d CC_OPTIMIZE_FOR_PERFORMANCE -e CC_OPTIMIZE_FOR_SIZE make -j72 ARCH=3Driscv CROSS_COMPILE=3Driscv64-linux-gnu- qemu-system-riscv64 -machine virt -smp 2 -m 4G -kernel arch/riscv/boot/Image -nographic -append "earlycon earlyprintk=3Dserial console=3DttyS0" [this boots fine, at least at to starting init process]